'Rerender a row from Datagrid without refresh the whole list
In a List
with DataGrid
, in each row I have a button for change status, on button click I show a modal with a form, after submit, in the response I have updated object with the same id and new status, I want to rerender only one row from data dataGrid and his child InvoiceShow
const InvoiceList = (props: ListProps) => {
return (
<List {...props}>
<Datagrid rowClick="expand" expand={<InvoiceShow />}>
<TextField source="id" />
<NumberField source="status" />
<Button onClick={() => setOpenDialog(true)} >
Update Status
</Button>
</Datagrid>
</List>
);
};
<Dialog open={setOpenDialog}>
<DialogTitle>Update Status</DialogTitle>
<DialogContent>
<form onSubmit={handleSubmit}>
...
</form>
</DialogContent>
</Dialog>
const handleSubmit= () => {
RequestManager.updateStatus()
.then((updatedInvoice) => {
//rerender
})
.catch((response) => {
handleCatch(response);
});
};
I can use refresh()
from useRefresh()
hooks, but this will increase the number of requests
Is there a way to rerender only one row from the Datagrid and if is expanded InvoiceShow
also?
Solution 1:[1]
Try with refetch
instead of refresh
refetch: A function you can call to trigger a refetch. It’s different from the refresh function returned by useRefresh as it won’t trigger a refresh of the view, only this specific query.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |