fix(data-table): table header keys should be reactive (#1346)

Fixes #1345

Co-authored-by: Jorge Vergara <jbvergara@bethel.jw.org>
This commit is contained in:
jorgebv 2022-06-12 21:09:33 -04:00 committed by GitHub
commit 0f060ea035
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -144,13 +144,8 @@
};
const dispatch = createEventDispatcher();
const batchSelectedIds = writable(false);
const headerItems = writable([]);
const tableRows = writable(rows);
const thKeys = derived(headerItems, () =>
headers
.map(({ key }) => ({ key, id: key }))
.reduce((a, c) => ({ ...a, [c.key]: c.id }), {})
);
$: thKeys = headers.reduce((a, c) => ({ ...a, [c.key]: c.key }), {});
const resolvePath = (object, path) => {
if (path in object) return object[path];
return path
@ -356,7 +351,7 @@
sortKey === header.key ? sortDirection : 'none';
sortDirection = sortDirectionMap[currentSortDirection];
sortKey =
sortDirection === 'none' ? null : $thKeys[header.key];
sortDirection === 'none' ? null : thKeys[header.key];
dispatch('click:header', { header, sortDirection });
}
}}"