-
-
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.
- Loading branch information
1 parent
6f88bda
commit 26a4ad9
Showing
13 changed files
with
430 additions
and
86 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
17 changes: 17 additions & 0 deletions
17
docs/src/pages/components/data-grid/pagination/200PaginationGrid.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,17 @@ | ||
import * as React from 'react'; | ||
import { XGrid } from '@material-ui/x-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
export default function BasisPaginationGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 1000, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<XGrid pagination pageSize={200} {...data} /> | ||
</div> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
docs/src/pages/components/data-grid/pagination/200PaginationGrid.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,17 @@ | ||
import * as React from 'react'; | ||
import { XGrid } from '@material-ui/x-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
export default function BasisPaginationGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 1000, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<XGrid pagination pageSize={200} {...data} /> | ||
</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
23 changes: 23 additions & 0 deletions
23
docs/src/pages/components/data-grid/rows/DisableSortingGrid.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 } from '@material-ui/data-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
export default function DisableSortingGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 1000, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
{...data} | ||
columns={data.columns.map((column) => ({ | ||
...column, | ||
sortable: false, | ||
}))} | ||
/> | ||
</div> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
docs/src/pages/components/data-grid/rows/DisableSortingGrid.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 } from '@material-ui/data-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
export default function DisableSortingGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 1000, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
{...data} | ||
columns={data.columns.map((column) => ({ | ||
...column, | ||
sortable: false, | ||
}))} | ||
/> | ||
</div> | ||
); | ||
} |
28 changes: 28 additions & 0 deletions
28
docs/src/pages/components/data-grid/rows/MultiSortingGrid.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,28 @@ | ||
import * as React from 'react'; | ||
import { XGrid } from '@material-ui/x-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
const sortModel = [ | ||
{ | ||
field: 'commodity', | ||
sort: 'asc', | ||
}, | ||
{ | ||
field: 'desk', | ||
sort: 'desc', | ||
}, | ||
]; | ||
|
||
export default function MultiSortingGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 1000, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<XGrid sortModel={sortModel} {...data} /> | ||
</div> | ||
); | ||
} |
28 changes: 28 additions & 0 deletions
28
docs/src/pages/components/data-grid/rows/MultiSortingGrid.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,28 @@ | ||
import * as React from 'react'; | ||
import { XGrid, SortDirection } from '@material-ui/x-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
const sortModel = [ | ||
{ | ||
field: 'commodity', | ||
sort: 'asc' as SortDirection, | ||
}, | ||
{ | ||
field: 'desk', | ||
sort: 'desc' as SortDirection, | ||
}, | ||
]; | ||
|
||
export default function MultiSortingGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 1000, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<XGrid sortModel={sortModel} {...data} /> | ||
</div> | ||
); | ||
} |
88 changes: 88 additions & 0 deletions
88
docs/src/pages/components/data-grid/rows/ServerSortingGrid.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,88 @@ | ||
import * as React from 'react'; | ||
import { DataGrid } from '@material-ui/data-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
function loadServerRows(sortModel, data) { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
if (sortModel.length === 0) { | ||
resolve(data.rows); | ||
return; | ||
} | ||
|
||
const sortedColumn = sortModel[0]; | ||
|
||
let sortedRows = [ | ||
...data.rows.sort((a, b) => | ||
String(a[sortedColumn.field]).localeCompare( | ||
String(b[sortedColumn.field]), | ||
), | ||
), | ||
]; | ||
|
||
if (sortModel[0].sort === 'desc') { | ||
sortedRows = sortedRows.reverse(); | ||
} | ||
|
||
resolve(sortedRows); | ||
}, Math.random() * 500 + 100); // simulate network latency | ||
}); | ||
} | ||
|
||
export default function ServerSortingGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 6, | ||
}); | ||
|
||
const [sortModel, setSortModel] = React.useState([ | ||
{ field: 'commodity', sort: 'asc' }, | ||
]); | ||
|
||
const [rows, setRows] = React.useState([]); | ||
const [loading, setLoading] = React.useState(false); | ||
|
||
const handleSortModelChange = (params) => { | ||
if (params.sortModel !== sortModel) { | ||
setSortModel(params.sortModel); | ||
} | ||
}; | ||
|
||
React.useEffect(() => { | ||
let active = true; | ||
|
||
(async () => { | ||
setLoading(true); | ||
const newRows = await loadServerRows(sortModel, data); | ||
|
||
if (!active) { | ||
return; | ||
} | ||
|
||
setRows(newRows); | ||
setLoading(false); | ||
})(); | ||
|
||
return () => { | ||
active = false; | ||
}; | ||
}, [sortModel, data]); | ||
|
||
if (data.columns.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
rows={rows} | ||
columns={data.columns} | ||
sortingMode="server" | ||
sortModel={sortModel} | ||
onSortModelChange={handleSortModelChange} | ||
loading={loading} | ||
/> | ||
</div> | ||
); | ||
} |
86 changes: 86 additions & 0 deletions
86
docs/src/pages/components/data-grid/rows/ServerSortingGrid.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,86 @@ | ||
import * as React from 'react'; | ||
import { RowsProp, DataGrid, SortModel } from '@material-ui/data-grid'; | ||
import { useDemoData, GridData } from '@material-ui/x-grid-data-generator'; | ||
|
||
function loadServerRows(sortModel: SortModel, data: GridData): Promise<any> { | ||
return new Promise<any>((resolve) => { | ||
setTimeout(() => { | ||
if (sortModel.length === 0) { | ||
resolve(data.rows); | ||
return; | ||
} | ||
|
||
const sortedColumn = sortModel[0]; | ||
|
||
let sortedRows = [ | ||
...data.rows.sort((a, b) => | ||
String(a[sortedColumn.field]).localeCompare( | ||
String(b[sortedColumn.field]), | ||
), | ||
), | ||
]; | ||
|
||
if (sortModel[0].sort === 'desc') { | ||
sortedRows = sortedRows.reverse(); | ||
} | ||
|
||
resolve(sortedRows); | ||
}, Math.random() * 500 + 100); // simulate network latency | ||
}); | ||
} | ||
|
||
export default function ServerSortingGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 6, | ||
}); | ||
const [sortModel, setSortModel] = React.useState<SortModel>([ | ||
{ field: 'commodity', sort: 'asc' }, | ||
]); | ||
const [rows, setRows] = React.useState<RowsProp>([]); | ||
const [loading, setLoading] = React.useState<boolean>(false); | ||
|
||
const handleSortModelChange = (params) => { | ||
if (params.sortModel !== sortModel) { | ||
setSortModel(params.sortModel); | ||
} | ||
}; | ||
|
||
React.useEffect(() => { | ||
let active = true; | ||
|
||
(async () => { | ||
setLoading(true); | ||
const newRows = await loadServerRows(sortModel, data); | ||
|
||
if (!active) { | ||
return; | ||
} | ||
|
||
setRows(newRows); | ||
setLoading(false); | ||
})(); | ||
|
||
return () => { | ||
active = false; | ||
}; | ||
}, [sortModel, data]); | ||
|
||
if (data.columns.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
rows={rows} | ||
columns={data.columns} | ||
sortingMode="server" | ||
sortModel={sortModel} | ||
onSortModelChange={handleSortModelChange} | ||
loading={loading} | ||
/> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.