feat: custom feat-custom-pagination
parent
3a4caa831e
commit
e0d896bb25
@ -0,0 +1,46 @@
|
||||
import * as React from 'react';
|
||||
import { DataGrid, gridPageSelector, gridPageCountSelector, useGridApiContext, useGridApiRef, useGridSelector } from '@mui/x-data-grid';
|
||||
import { useDemoData } from '@mui/x-data-grid-generator';
|
||||
import Pagination from '@mui/material/Pagination';
|
||||
|
||||
const Toolbar = () => {
|
||||
const apiRef = useGridApiContext();
|
||||
const page = useGridSelector(apiRef, gridPageSelector);
|
||||
const pageCount = useGridSelector(apiRef, gridPageCountSelector);
|
||||
|
||||
return (
|
||||
<Pagination
|
||||
sx={(theme) => ({ padding: theme.spacing(1.5, 0) })}
|
||||
color="primary"
|
||||
count={pageCount}
|
||||
page={page + 1}
|
||||
onChange={(event, value) => apiRef.current.setPage(value - 1)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default function UseGridSelector() {
|
||||
const { data, loading } = useDemoData({
|
||||
dataSet: 'Commodity',
|
||||
rowLength: 100,
|
||||
maxColumns: 10
|
||||
});
|
||||
|
||||
const apiRef = useGridApiRef();
|
||||
|
||||
return (
|
||||
<div style={{ height: 400, width: '100%' }}>
|
||||
<DataGrid
|
||||
{...data}
|
||||
loading={loading}
|
||||
apiRef={apiRef}
|
||||
pagination
|
||||
pageSize={10}
|
||||
// hideFooter
|
||||
components={{
|
||||
Toolbar
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue