Im trying to integrate AG Grid server side model with Redux Toolkit Query but problem is I have external parameters that changes, but did not find how to handle this.
I have pagination/filters/sorting on, I think I cant just override the datasource or I might lose them?
Heres an example
function MyGrid({ param1, param2 }: props): ReactElement {
// param1/param2 are updated here
const [triggerPostData] = usePostDataMutation();
const createDatasource: () => IServerSideDatasource = useCallback(() => {
return {
getRows: (parameters): void => {
// param1/param2 arent updated here
triggerPostData({ param1, param2, rowsRequestData: parameters.request })
.unwrap()
.then((data) => {
parameters.success({
rowData: data.results,
rowCount: data.resultCount
});
return parameters;
})
.catch(() => {
parameters.fail();
});
}
};
}, [param1, param2, triggerPostData]);
const onGridReady = useCallback(
(parameters: GridReadyEvent): void => {
parameters.api.setServerSideDatasource(createDatasource());
},
[createDatasource]
);
const agGridProperties: AgGridReactProps = {
columnDefs,
rowModelType: 'serverSide',
cacheBlockSize: paginationPageSize,
onGridReady
};
return <AgGridReact {...agGridProperties} />;
}
RTK Query author here.
Honestly, from personal experience with AG-Grid's DataSources: If you have no need to use a third-party tool like RTK Query, just use normal fetch straight out of the box.
AG-Grid has its own cache and wants a lot of control over which request is made when - and RTK Query kinda does the same job. Instead of having two tools fight over "who does what", just use one tool. You don't need both in this instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With