You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to add some extra functionality to the row model, to be able to store some metadata and functions to interact with that data.
I had thought I got it right, but i've created some incorrect behavior doing this.
Here is my custom row model:
import {
getCoreRowModel,
} from '@tanstack/react-table';
const customRowModelFunction = (table) => {
let model = getCoreRowModel()
let newmodel = model(table)();
// Iterate over rows and add custom functions or metadata
for (const row of newmodel.rows) {
row.meta = {
saved: false
};
//set the saved state for 2 seconds
row.rowSaved = () => {
row.meta.saved = true
setTimeout(() => {
row.meta.saved = false
}, 2000)
}
row.getIsSaved = () => row.meta.saved
}
return () => newmodel;
};
export default customRowModelFunction;
I've simply added some functionality so that I can style a row when it's data has been saved.
I then add it to my table like this:
This appeared to work for a time, but I realized after some hair pulling that my custom model was causing my rows to not update.
Specifially the values returned by table.getRowModel() that I use to itterate through and create my rows. Even though the table data was being updated, the rows from this function never changed from their original state.
Can someone point my in the direction I need to correctly extend the row model? There's not really any documentation on this.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I wanted to add some extra functionality to the row model, to be able to store some metadata and functions to interact with that data.
I had thought I got it right, but i've created some incorrect behavior doing this.
Here is my custom row model:
I've simply added some functionality so that I can style a row when it's data has been saved.
I then add it to my table like this:
This appeared to work for a time, but I realized after some hair pulling that my custom model was causing my rows to not update.
Specifially the values returned by
table.getRowModel()
that I use to itterate through and create my rows. Even though the table data was being updated, the rows from this function never changed from their original state.Can someone point my in the direction I need to correctly extend the row model? There's not really any documentation on this.
Beta Was this translation helpful? Give feedback.
All reactions