Skip to content

Row Selection

Add a checkbox column with enableRowSelection:

<MaterialSvelteTable options={{ columns, data, enableRowSelection: true }} />

Read the selection from the table instance, or manage it as state:

<script lang="ts">
let rowSelection = $state<MRT_RowSelectionState>({});
</script>
<MaterialSvelteTable
options={{
columns,
data,
enableRowSelection: true,
getRowId: (row) => row.id,
onRowSelectionChange: (updater) => {
rowSelection = typeof updater === 'function' ? updater(rowSelection) : updater;
},
state: {
get rowSelection() {
return rowSelection;
},
},
}}
/>

The selection is keyed by row id. Without getRowId the id is the row index, so set it whenever you store the selection, otherwise it will point at the wrong rows after sorting or reloading.

OptionWhat it does
enableRowSelectiontrue, or a function (row) => boolean to choose which rows can be selected.
enableMultiRowSelectionSet false for single selection (radio buttons).
enableSelectAllShow or hide the select all checkbox.
selectAllMode'page' (default) selects the current page; 'all' selects every filtered row.
enableBatchRowSelectionShift-click to select a range. On by default.
enableSubRowSelectionSelecting a parent also selects its children.
selectCheckboxPropsProps for each checkbox, such as color or disabled.

The checkbox column is optional. To select when the row is clicked, use tableBodyRowProps:

<MaterialSvelteTable
options={{
columns,
data,
enableRowSelection: true,
tableBodyRowProps: ({ row }) => ({
onclick: row.getToggleSelectedHandler(),
style: 'cursor: pointer',
}),
}}
/>

When rows are selected a banner shows the count. Move it with positionToolbarAlertBanner ('top', 'bottom', 'head-overlay' or 'none'), or replace its content with the toolbarAlertBannerContent snippet.