mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
fix(DataTable): undefined cell value fallback (#745)
* fix(DataTable): undefined cell value fallback * Update DataTable.svelte * fix(data-table): remove "" as the default value for table cells Co-authored-by: Eric Y Liu <ericyl.us@gmail.com>
This commit is contained in:
parent
51ebf185b5
commit
89513fb4cb
1 changed files with 3 additions and 6 deletions
|
@ -127,14 +127,11 @@
|
||||||
.map(({ key }, i) => ({ key, id: $headerItems[i] }))
|
.map(({ key }, i) => ({ key, id: $headerItems[i] }))
|
||||||
.reduce((a, c) => ({ ...a, [c.key]: c.id }), {})
|
.reduce((a, c) => ({ ...a, [c.key]: c.id }), {})
|
||||||
);
|
);
|
||||||
const resolvePath = (object, path, defaultValue) =>
|
const resolvePath = (object, path) =>
|
||||||
path
|
path
|
||||||
.split(/[\.\[\]\'\"]/)
|
.split(/[\.\[\]\'\"]/)
|
||||||
.filter((p) => p)
|
.filter((p) => p)
|
||||||
.reduce(
|
.reduce((o, p) => (o && typeof o === "object" ? o[p] : o), object);
|
||||||
(o, p) => (o && typeof o === "object" && o[p] ? o[p] : defaultValue),
|
|
||||||
object
|
|
||||||
);
|
|
||||||
|
|
||||||
setContext("DataTable", {
|
setContext("DataTable", {
|
||||||
sortHeader,
|
sortHeader,
|
||||||
|
@ -172,7 +169,7 @@
|
||||||
...row,
|
...row,
|
||||||
cells: headerKeys.map((key, index) => ({
|
cells: headerKeys.map((key, index) => ({
|
||||||
key,
|
key,
|
||||||
value: resolvePath(row, key, ""),
|
value: resolvePath(row, key),
|
||||||
display: headers[index].display,
|
display: headers[index].display,
|
||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue