T
TanStack2y ago
eastern-cyan

Refresh datatable after delete from dropdownmenu

Hi i currently have a project where i use tanstack table, but ive run into an issue as i dont know how to refresh the table after i have deleted a entry from my table, i use a api call for deleting of the entry and question is what to do next? Data is fetched from my api .
await auth.deleteGroup(id); // group gets deleted by id,

// Somehow refresh datatable
await auth.deleteGroup(id); // group gets deleted by id,

// Somehow refresh datatable
2 Replies
plain-purple
plain-purple2y ago
Once the delete action is completed, you need to refetch the data. Sort of like this
async function delteGroup(id) {
await auth.delteGroup(id);
await refetchData() // over here you refetch the data and provide it to the used table hook
// Essentially you need to invalidate the server cache from you app, and ensure it triggers a refetch.
// Like when the app first loads and you need to get all the data.
}
async function delteGroup(id) {
await auth.delteGroup(id);
await refetchData() // over here you refetch the data and provide it to the used table hook
// Essentially you need to invalidate the server cache from you app, and ensure it triggers a refetch.
// Like when the app first loads and you need to get all the data.
}
national-gold
national-gold2y ago
the table will rerender anytime your data changes

Did you find this page helpful?