-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Continue the migration of the demos
- Loading branch information
1 parent
a2bd9da
commit 72a8b3a
Showing
14 changed files
with
188 additions
and
656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
docs/src/pages/components/data-grid/pagination/ApiRefPaginationGrid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
import { DataGrid, useApiRef } from '@material-ui/data-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
export default function ApiRefPaginationGrid() { | ||
const apiRef = useApiRef(); | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 6, | ||
}); | ||
|
||
React.useEffect(() => { | ||
console.log('hello', apiRef.current); | ||
apiRef.current.setPage(2); | ||
}, [apiRef]); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid pagination pageSize={5} apiRef={apiRef} {...data} /> | ||
</div> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
docs/src/pages/components/data-grid/pagination/ApiRefPaginationGrid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
import { DataGrid, useApiRef } from '@material-ui/data-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
export default function ApiRefPaginationGrid() { | ||
const apiRef = useApiRef(); | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 6, | ||
}); | ||
|
||
React.useEffect(() => { | ||
console.log('hello', apiRef.current) | ||
apiRef.current.setPage(2); | ||
}, [apiRef]); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid pagination pageSize={5} apiRef={apiRef} {...data} /> | ||
</div> | ||
); | ||
} |
62 changes: 62 additions & 0 deletions
62
docs/src/pages/components/data-grid/pagination/ServerPaginationGrid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as React from 'react'; | ||
import { DataGrid } from '@material-ui/data-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
function loadServerRows(page, data) { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(data.rows.slice((page - 1) * 5, page * 5)); | ||
}, Math.random() * 500 + 100); | ||
}); | ||
} | ||
|
||
export default function ServerPaginationGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 100, | ||
maxColumns: 6, | ||
}); | ||
|
||
const [page, setPage] = React.useState(1); | ||
const [rows, setRows] = React.useState([]); | ||
const [loading, setLoading] = React.useState(false); | ||
|
||
const handlePageChange = (params) => { | ||
setPage(params.page); | ||
}; | ||
|
||
React.useEffect(() => { | ||
let active = true; | ||
|
||
(async () => { | ||
setLoading(true); | ||
const newRows = await loadServerRows(page, data); | ||
|
||
if (!active) { | ||
return; | ||
} | ||
|
||
setRows(newRows); | ||
setLoading(false); | ||
})(); | ||
|
||
return () => { | ||
active = false; | ||
}; | ||
}, [page, data]); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
rows={rows} | ||
columns={data.columns} | ||
pagination | ||
pageSize={5} | ||
rowCount={100} | ||
paginationMode="server" | ||
onPageChange={handlePageChange} | ||
loading={loading} | ||
/> | ||
</div> | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
docs/src/pages/components/data-grid/pagination/ServerPaginationGrid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as React from 'react'; | ||
import { RowsProp, DataGrid } from '@material-ui/data-grid'; | ||
import { useDemoData, GridData } from '@material-ui/x-grid-data-generator'; | ||
|
||
function loadServerRows(page: number, data: GridData): Promise<any> { | ||
return new Promise<any>((resolve) => { | ||
setTimeout(() => { | ||
resolve(data.rows.slice((page - 1) * 5, page * 5)); | ||
}, Math.random() * 500 + 100); | ||
}); | ||
} | ||
|
||
export default function ServerPaginationGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 100, | ||
maxColumns: 6, | ||
}); | ||
const [page, setPage] = React.useState(1); | ||
const [rows, setRows] = React.useState<RowsProp>([]); | ||
const [loading, setLoading] = React.useState<boolean>(false); | ||
|
||
const handlePageChange = (params) => { | ||
setPage(params.page); | ||
}; | ||
|
||
React.useEffect(() => { | ||
let active = true; | ||
|
||
(async () => { | ||
setLoading(true); | ||
const newRows = await loadServerRows(page, data); | ||
|
||
if (!active) { | ||
return; | ||
} | ||
|
||
setRows(newRows); | ||
setLoading(false); | ||
})(); | ||
|
||
return () => { | ||
active = false; | ||
}; | ||
}, [page, data]); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
rows={rows} | ||
columns={data.columns} | ||
pagination | ||
pageSize={5} | ||
rowCount={100} | ||
paginationMode="server" | ||
onPageChange={handlePageChange} | ||
loading={loading} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 0 additions & 93 deletions
93
packages/storybook/src/documentation/pages/demos/pagination/autoPageSize.demo.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.