mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
bugfix: handle table update when column is missing
This commit is contained in:
parent
217a4d65fd
commit
ce6aaa709f
1 changed files with 4 additions and 9 deletions
|
|
@ -33,16 +33,17 @@ export const useTableChange = (
|
|||
const api = tableRef.current?.api;
|
||||
if (!api) return;
|
||||
|
||||
const rowNodes: RowNode[] = [];
|
||||
const idSet = new Set(ids);
|
||||
|
||||
api.forEachNode((node: RowNode<Song>) => {
|
||||
if (!node.data || !idSet.has(node.data.id)) return;
|
||||
|
||||
// Make sure to use setData instead of setDataValue. setDataValue
|
||||
// will error if the column does not exist, whereas setData won't care
|
||||
switch (event.event) {
|
||||
case 'favorite': {
|
||||
if (node.data.userFavorite !== event.favorite) {
|
||||
node.setDataValue('userFavorite', event.favorite);
|
||||
node.setData({ ...node.data, userFavorite: event.favorite });
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -58,18 +59,12 @@ export const useTableChange = (
|
|||
break;
|
||||
case 'rating': {
|
||||
if (node.data.userRating !== event.rating) {
|
||||
node.setDataValue('userRating', event.rating);
|
||||
rowNodes.push(node);
|
||||
node.setData({ ...node.data, userRating: event.rating });
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// This is required to redraw star rows
|
||||
if (rowNodes.length > 0) {
|
||||
api.redrawRows({ rowNodes });
|
||||
}
|
||||
},
|
||||
[tableRef],
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue