Replies: 2 comments 3 replies
-
Has anyone figured out how to make |
Beta Was this translation helpful? Give feedback.
3 replies
-
I made a custom // imorts
// created a wrapper function for a closure to store the details we need.
export const createGetSortedRowModel = () => {
let filter = '';
// right now we store the entire model, we could probably just store an array of ids instead
let previousRowModel: any;
return function getSortedRowModel<TData extends RowData>(): (
table: Table<TData>,
) => () => RowModel<TData> {
return table =>
memo(
() => [
table.getState().sorting,
// added in the filter so this gets invoked on filter change
table.getState().globalFilter,
table.getPreSortedRowModel(),
],
(sorting, globalFilter, rowModel) => {
if (!rowModel.rows.length || !sorting?.length) {
previousRowModel = rowModel;
return rowModel;
}
// default the previous
if (!previousRowModel?.rows?.length) previousRowModel = rowModel;
// when this is triggered by a filter change we default to the previous sorting model but using
// the filter model as the source of truth for the items available
if (
filter !== JSON.stringify(globalFilter) &&
previousRowModel.rows.length >= rowModel.rows.length
) {
filter = JSON.stringify(table.getState().globalFilter);
const newRowModel: RowModel<TData> = {
rows: previousRowModel.rows.reduce(
(acc: Row<TData>[], row: Row<TData>) => {
const existing = rowModel.rowsById[row.id];
if (existing) acc.push(existing);
return acc;
},
[] as Row<TData>[],
),
flatRows: previousRowModel.rows.reduce(
(acc: Row<TData>[], row: Row<TData>) => {
const existing = rowModel.rowsById[row.id];
if (existing) acc.push(existing);
return acc;
},
[] as Row<TData>[],
),
rowsById: rowModel.rowsById,
};
previousRowModel = newRowModel;
return newRowModel;
}
// rest of the sorting model from tanstack
// we assign the row model so we can store it in the closure
const newRowModel = {
rows: sortData(rowModel.rows),
flatRows: sortedFlatRows,
rowsById: rowModel.rowsById,
};
previousRowModel = newRowModel;
return newRowModel;
},
{
key: process.env.NODE_ENV === 'development' && 'getSortedRowModel',
debug: () => table.options.debugAll ?? table.options.debugTable,
onChange: () => {
table._autoResetPageIndex();
},
},
);
};
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have searched the docs and issues but I did not find the answer on how to migrate
autoReset*
functionality to v8.In v7 this is how it looked:
I used this functionality to reset sorting/filtering when a new item was added to the table (the latest items were at the start of the table) but I could also turn it off when the user changed an item they found with filters/sorting.
Now all there is:
So I don't know if I am missing some thing, or should I need to write some code that checks if
myControlledBooleanVariable
and then it calls some reset functions?Beta Was this translation helpful? Give feedback.
All reactions