-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs] Migrate sorting #233
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
); | ||
} |
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> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -50,10 +50,22 @@ Finally, you need to handle the `onPageChange` callback to load the rows for the | |||||
|
||||||
## apiRef | ||||||
|
||||||
We exposed a set of methods that will let you achieve all the above features using the imperative apiRef. | ||||||
The Grid exposes a set of methods that will let you achieve all the above features using the imperative apiRef. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
> ⚠️ Only use this API when you have no alternatives. Always start from the declarative APIs the Grid exposes. | ||||||
> ⚠️ Only use this API when you have no alternatives. Always start from the declarative API the Grid exposes. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
- `setPageSize` | ||||||
- `setPage` | ||||||
- `onPageChange` | ||||||
- `onPageSizeChange` | ||||||
|
||||||
Below is an example on how you can reset the page using the imperative `setPage` method. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
{{"demo": "pages/components/data-grid/pagination/ApiRefPaginationGrid.js"}} | ||||||
|
||||||
## Paginate > 100 rows ✨ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
"✨" = "new feature". If this is meant to indicate a premium feature, it needs a more appropriate icon. (See suggestions elsewhere). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mean to indicate premium, happy to use a different one, for now, the objective is to have at least one. |
||||||
|
||||||
The `DataGrid` component can display up to 100 rows per page. | ||||||
The `XGrid` component removes this limitation, the following demo displays 200 rows per page: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
{{"demo": "pages/components/data-grid/pagination/200PaginationGrid.js"}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
import { DataGrid } from '@material-ui/data-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
const sortModel = [ | ||
{ | ||
field: 'commodity', | ||
sort: 'asc', | ||
}, | ||
]; | ||
|
||
export default function BasicSortingGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid sortModel={sortModel} {...data} /> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
import { DataGrid, SortDirection } from '@material-ui/data-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
|
||
const sortModel = [ | ||
{ | ||
field: 'commodity', | ||
sort: 'asc' as SortDirection, | ||
}, | ||
]; | ||
|
||
export default function BasicSortingGrid() { | ||
const { data } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid sortModel={sortModel} {...data} /> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import * as React from 'react'; | ||
import { DataGrid } from '@material-ui/data-grid'; | ||
import { | ||
randomCreatedDate, | ||
randomUpdatedDate, | ||
} from '@material-ui/x-grid-data-generator'; | ||
|
||
const columns = [ | ||
{ field: 'id', hide: true }, | ||
{ field: 'name' }, | ||
{ field: 'age', type: 'number' }, | ||
{ | ||
field: 'username', | ||
valueGetter: (params) => | ||
`${params.getValue('name') || 'unknown'} - ${ | ||
params.getValue('age') || 'x' | ||
}`, | ||
sortComparator: (v1, v2, row1, row2) => row1.data.age - row2.data.age, | ||
width: 150, | ||
}, | ||
{ field: 'dateCreated', type: 'date', width: 180 }, | ||
{ field: 'lastLogin', type: 'dateTime', width: 180 }, | ||
]; | ||
|
||
const rows = [ | ||
{ | ||
id: 1, | ||
name: 'Damien', | ||
age: 25, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Nicolas', | ||
age: 36, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Kate', | ||
age: 19, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 4, | ||
name: 'Sebastien', | ||
age: 28, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 5, | ||
name: 'Louise', | ||
age: 23, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 6, | ||
name: 'George', | ||
age: 10, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
]; | ||
|
||
const sortModel = [ | ||
{ | ||
field: 'username', | ||
sort: 'asc', | ||
}, | ||
]; | ||
|
||
export default function ComparatorSortingGrid() { | ||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid sortModel={sortModel} rows={rows} columns={columns} /> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import * as React from 'react'; | ||
import { | ||
Columns, | ||
RowsProp, | ||
DataGrid, | ||
SortDirection, | ||
} from '@material-ui/data-grid'; | ||
import { | ||
randomCreatedDate, | ||
randomUpdatedDate, | ||
} from '@material-ui/x-grid-data-generator'; | ||
|
||
const columns: Columns = [ | ||
{ field: 'id', hide: true }, | ||
{ field: 'name' }, | ||
{ field: 'age', type: 'number' }, | ||
{ | ||
field: 'username', | ||
valueGetter: (params) => | ||
`${params.getValue('name') || 'unknown'} - ${ | ||
params.getValue('age') || 'x' | ||
}`, | ||
sortComparator: (v1, v2, row1, row2) => row1.data.age - row2.data.age, | ||
width: 150, | ||
}, | ||
{ field: 'dateCreated', type: 'date', width: 180 }, | ||
{ field: 'lastLogin', type: 'dateTime', width: 180 }, | ||
]; | ||
|
||
const rows: RowsProp = [ | ||
{ | ||
id: 1, | ||
name: 'Damien', | ||
age: 25, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Nicolas', | ||
age: 36, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Kate', | ||
age: 19, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 4, | ||
name: 'Sebastien', | ||
age: 28, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 5, | ||
name: 'Louise', | ||
age: 23, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
{ | ||
id: 6, | ||
name: 'George', | ||
age: 10, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
]; | ||
|
||
const sortModel = [ | ||
{ | ||
field: 'username', | ||
sort: 'asc' as SortDirection, | ||
}, | ||
]; | ||
|
||
export default function ComparatorSortingGrid() { | ||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid sortModel={sortModel} rows={rows} columns={columns} /> | ||
</div> | ||
); | ||
} |
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: 10, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
{...data} | ||
columns={data.columns.map((column) => ({ | ||
...column, | ||
sortable: false, | ||
}))} | ||
/> | ||
</div> | ||
); | ||
} |
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: 10, | ||
maxColumns: 6, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
{...data} | ||
columns={data.columns.map((column) => ({ | ||
...column, | ||
sortable: false, | ||
}))} | ||
/> | ||
</div> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.