useSelection
Get the recordId and fieldId of the region selected by the current cell cursor. Rerendering is triggered when the cursor is moved or the view is switched.
If you only need information about the active cell, please use useActiveCell.
Returns
undefined
| { recordIds
: string
[] ; fieldIds
: string
[] }
Example
import { useSelection, useRecords, useFields, useActiveViewId } from '@apitable/widget-sdk';
// Render the currently selection information
function Selection() {
const selection = useSelection();
const viewId = useActiveViewId();
const records = useRecords(viewId, { ids: selection?.recordIds });
const fields = useFields(viewId, { ids: selection?.fieldIds });
return (<table>
<thead>
<tr>
{fields.map(field => <th key={field.id}>{field.name || '_'}</th>)}
</tr>
</thead>
<tbody>
{records.map(record =>
<tr key={record.id}>
{fields.map(field =>
<td key={field.id}>{record.getCellValueString(field.id) || '_'}</td>
)}
</tr>
)}
</tbody>
</table>);
}