-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerSideLazyLoadingInfinite.js
44 lines (39 loc) · 1.16 KB
/
ServerSideLazyLoadingInfinite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as React from 'react';
import { DataGridPro } from '@mui/x-data-grid-pro';
import { useMockServer } from '@mui/x-data-grid-generator';
function ServerSideLazyLoadingInfinite() {
const { fetchRows, ...props } = useMockServer(
{ rowLength: 100 },
{ useCursorPagination: false, minDelay: 200, maxDelay: 500 },
);
const dataSource = React.useMemo(
() => ({
getRows: async (params) => {
const urlParams = new URLSearchParams({
filterModel: JSON.stringify(params.filterModel),
sortModel: JSON.stringify(params.sortModel),
start: `${params.start}`,
end: `${params.end}`,
});
const getRowsResponse = await fetchRows(
`https://mui.com/x/api/data-grid?${urlParams.toString()}`,
);
return {
rows: getRowsResponse.rows,
};
},
}),
[fetchRows],
);
return (
<div style={{ width: '100%', height: 400 }}>
<DataGridPro
{...props}
unstable_dataSource={dataSource}
unstable_lazyLoading
paginationModel={{ page: 0, pageSize: 15 }}
/>
</div>
);
}
export default ServerSideLazyLoadingInfinite;