feat(data-table): add nonSelectableRowIds prop

Closes #1148
This commit is contained in:
Eric Liu 2022-03-12 19:04:31 -08:00
commit 5c48fe76d1

View file

@ -94,6 +94,12 @@
*/ */
export let selectedRowIds = []; export let selectedRowIds = [];
/**
* Specify the ids of rows that should not be selectable
* @type {DataTableRowId[]}
*/
export let nonSelectableRowIds = [];
/** Set to `true` to enable a sticky header */ /** Set to `true` to enable a sticky header */
export let stickyHeader = false; export let stickyHeader = false;
@ -171,6 +177,9 @@
$: expandableRowIds = rows $: expandableRowIds = rows
.map((row) => row.id) .map((row) => row.id)
.filter((id) => !nonExpandableRowIds.includes(id)); .filter((id) => !nonExpandableRowIds.includes(id));
$: selectableRowIds = rows
.map((row) => row.id)
.filter((id) => !nonSelectableRowIds.includes(id));
$: indeterminate = $: indeterminate =
selectedRowIds.length > 0 && selectedRowIds.length < rows.length; selectedRowIds.length > 0 && selectedRowIds.length < rows.length;
$: if (batchExpansion) { $: if (batchExpansion) {
@ -293,7 +302,7 @@
} }
if (e.target.checked) { if (e.target.checked) {
selectedRowIds = rows.map((row) => row.id); selectedRowIds = selectableRowIds;
} else { } else {
selectedRowIds = []; selectedRowIds = [];
} }
@ -405,6 +414,7 @@
class:bx--table-column-checkbox="{true}" class:bx--table-column-checkbox="{true}"
class:bx--table-column-radio="{radio}" class:bx--table-column-radio="{radio}"
> >
{#if !nonSelectableRowIds.includes(row.id)}
{#if radio} {#if radio}
<RadioButton <RadioButton
name="select-row-{row.id}" name="select-row-{row.id}"
@ -428,6 +438,7 @@
}}" }}"
/> />
{/if} {/if}
{/if}
</td> </td>
{/if} {/if}
{#each row.cells as cell, j (cell.key)} {#each row.cells as cell, j (cell.key)}