refactor(data-table): do not overwrite cells property

#667
This commit is contained in:
Eric Liu 2022-06-05 10:48:35 -07:00
commit 0a6b8fc112
2 changed files with 14 additions and 10 deletions

View file

@ -195,14 +195,18 @@
$: if (radio || batchSelection) selectable = true;
$: tableSortable.set(sortable);
$: headerKeys = headers.map(({ key }) => key);
$: $tableRows = rows.map((row) => ({
...row,
cells: headerKeys.map((key, index) => ({
key,
value: resolvePath(row, key),
display: headers[index].display,
})),
}));
$: tableCellsByRowId = rows.reduce(
(rows, row) => ({
...rows,
[row.id]: headerKeys.map((key, index) => ({
key,
value: resolvePath(row, key),
display: headers[index].display,
})),
}),
{}
);
$: $tableRows = rows;
$: sortedRows = [...$tableRows];
$: ascending = $sortHeader.sortDirection === "ascending";
$: sortKey = $sortHeader.key;
@ -464,7 +468,7 @@
{/if}
</td>
{/if}
{#each row.cells as cell, j (cell.key)}
{#each tableCellsByRowId[row.id] as cell, j (cell.key)}
{#if headers[j].empty}
<td class:bx--table-column-menu="{headers[j].columnMenu}">
<slot

View file

@ -50,7 +50,7 @@
if (shouldFilterRows === true) {
rows = rows.filter((row) => {
return Object.entries(row)
.filter(([key]) => !["cells", "id"].includes(key))
.filter(([key]) => key !== "id")
.some(([key, _value]) => {
if (typeof _value === "string" || typeof _value === "number") {
return (_value + "")