mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-16 02:41:05 +00:00
fix(data-table): handle ToolbarSearch
filtering in DataTable
(#2037)
This commit is contained in:
parent
1acd713537
commit
3192824322
2 changed files with 36 additions and 24 deletions
|
@ -49,32 +49,10 @@
|
|||
import { tick, getContext } from "svelte";
|
||||
import Search from "../Search/Search.svelte";
|
||||
|
||||
const { tableRows } = getContext("DataTable") ?? {};
|
||||
const ctx = getContext("DataTable") ?? {};
|
||||
|
||||
$: originalRows = tableRows ? [...$tableRows] : [];
|
||||
$: if (shouldFilterRows) {
|
||||
let rows = originalRows;
|
||||
|
||||
if (value.trim().length > 0) {
|
||||
if (shouldFilterRows === true) {
|
||||
rows = rows.filter((row) => {
|
||||
return Object.entries(row)
|
||||
.filter(([key]) => key !== "id")
|
||||
.some(([key, _value]) => {
|
||||
if (typeof _value === "string" || typeof _value === "number") {
|
||||
return (_value + "")
|
||||
?.toLowerCase()
|
||||
.includes(value.trim().toLowerCase());
|
||||
}
|
||||
});
|
||||
});
|
||||
} else if (typeof shouldFilterRows === "function") {
|
||||
rows = rows.filter((row) => shouldFilterRows(row, value) ?? false);
|
||||
}
|
||||
}
|
||||
|
||||
tableRows.set(rows);
|
||||
filteredRowIds = rows.map((row) => row.id);
|
||||
filteredRowIds = ctx?.filterRows(value, shouldFilterRows);
|
||||
}
|
||||
|
||||
async function expandSearch() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue