ratty-blush
ratty-blush9mo ago

useDataGrid refresh

using useDataGrid , how can I create a function to trigger a data reload event ? I need something like <RefreshButton> but with lower level code to trigger the data refresh event
2 Replies
kapa.ai
kapa.ai9mo ago
Hi @dannywhiteagile. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In Refine, you can manually trigger a data reload using the refetch function provided by the queryResult or tableQueryResult returned from the useTable or useForm hooks. This can be used in conjunction with useDataGrid. Here's an example of how you can use the refetch function with useTable:
import { useTable } from "@refinedev/core";

const { tableQueryResult: { refetch } } = useTable();

// Call refetch() whenever you want to fetch the data again
refetch();
import { useTable } from "@refinedev/core";

const { tableQueryResult: { refetch } } = useTable();

// Call refetch() whenever you want to fetch the data again
refetch();
And here's an example with useForm:
const { queryResult: { refetch } } = useForm();

// Call refetch() whenever you want to fetch the data again
refetch();
const { queryResult: { refetch } } = useForm();

// Call refetch() whenever you want to fetch the data again
refetch();
In these examples, refetch() is used to manually trigger the API call. You can call this function wherever you need to refresh the data. Sources: - Discord support thread: How to re-run useDataGrid? (https://discord.com/channels/837692625737613362/1105974721033555978) - Discord support thread: useForm (https://discord.com/channels/837692625737613362/1158263375562817566) - Discord support thread: Refreshing via RefreshButton & On an Interval (https://discord.com/channels/837692625737613362/1127658621724016690) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@1129002557419827210> kapa.ai is still learning and improving, please let us know how it did by reacting below