Skip to content

Commit

Permalink
[docs] Migrate sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Aug 29, 2020
1 parent 6f88bda commit cde884d
Show file tree
Hide file tree
Showing 28 changed files with 776 additions and 817 deletions.
43 changes: 27 additions & 16 deletions docs/src/pages/components/data-grid/accessibility/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,37 @@ The grid responds to keyboard interactions from the user as well as emitting eve

Use the arrow keys to move the focus.

| Keys | Description |
| -----------------------------------: | :-------------------------------------------- |
| <kbd>Tab</kbd> | Navigate between selectable elements |
| <kbd>Arrow Left</kbd> | Navigate between cell elements |
| <kbd>Arrow Bottom</kbd> | Navigate between cell elements |
| <kbd>Arrow Right</kbd> | Navigate between cell elements |
| <kbd>Arrow Up</kbd> | Navigate between cell elements |
| <kbd>Home</kbd> | Navigate to the first cell of the current row |
| <kbd>End</kbd> | Navigate to the last cell of the current row |
| <kbd>Control</kbd> + <kbd>Home</kbd> | Navigate to the first cell of the first row |
| <kbd>Control</kbd> + <kbd>End</kbd> | Navigate to the last cell of the last row |
| <kbd>Space</kbd> | Navigate to the next scrollable page |
| <kbd>Page Up</kbd> | Navigate to the next scrollable page |
| <kbd>Page Down</kbd> | Navigate to the previous scrollable page |
| Keys | Description |
| --------------------------------: | :-------------------------------------------- |
| <kbd>Tab</kbd> | Navigate between selectable elements |
| <kbd>Arrow Left</kbd> | Navigate between cell elements |
| <kbd>Arrow Bottom</kbd> | Navigate between cell elements |
| <kbd>Arrow Right</kbd> | Navigate between cell elements |
| <kbd>Arrow Up</kbd> | Navigate between cell elements |
| <kbd>Home</kbd> | Navigate to the first cell of the current row |
| <kbd>End</kbd> | Navigate to the last cell of the current row |
| <kbd>CTRL</kbd> + <kbd>Home</kbd> | Navigate to the first cell of the first row |
| <kbd>CTRL</kbd> + <kbd>End</kbd> | Navigate to the last cell of the last row |
| <kbd>Space</kbd> | Navigate to the next scrollable page |
| <kbd>Page Up</kbd> | Navigate to the next scrollable page |
| <kbd>Page Down</kbd> | Navigate to the previous scrollable page |

### Selection

| Keys | Description |
| -------------------------------------------------------------: | :------------------------------------------------ |
| <kbd>Shift</kbd> + <kbd>Space</kbd> | Select the current row |
| <kbd>Shift</kbd> + <kbd>Space</kbd> + <kbd>Arrow Up/Down</kbd> | Select the current row and the row above or below |
| <kbd>Control</kbd> + <kbd>A</kbd> | Select all rows |
| <kbd>Control</kbd> + <kbd>C</kbd> | Copy the currently selected row |
| <kbd>CTRL</kbd> + <kbd>A</kbd> | Select all rows |
| <kbd>CTRL</kbd> + <kbd>C</kbd> | Copy the currently selected row |

### Sorting

| Keys | Description |
| ----------------------: | :------------------- |
| <kbd>CTRL</kbd> + Click | Enable multi-sorting |

### Key assignment conventions

The above key assignments are defined in the context of Windows and Linux.
On macOS, replace <kbd>CTRL</kbd> with <kbd>⌘ Command</kbd>.
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>
);
}
16 changes: 14 additions & 2 deletions docs/src/pages/components/data-grid/pagination/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

> ⚠️ 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.
- `setPageSize`
- `setPage`
- `onPageChange`
- `onPageSizeChange`

Below is an example on how you can reset the page using the imperative `setPage` method.

{{"demo": "pages/components/data-grid/pagination/ApiRefPaginationGrid.js"}}

## Paginate > 100 rows ✨

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:

{{"demo": "pages/components/data-grid/pagination/200PaginationGrid.js"}}
24 changes: 24 additions & 0 deletions docs/src/pages/components/data-grid/rows/BasicSortingGrid.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>
);
}
24 changes: 24 additions & 0 deletions docs/src/pages/components/data-grid/rows/BasicSortingGrid.tsx
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>
);
}
83 changes: 83 additions & 0 deletions docs/src/pages/components/data-grid/rows/ComparatorSortingGrid.js
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>
);
}
88 changes: 88 additions & 0 deletions docs/src/pages/components/data-grid/rows/ComparatorSortingGrid.tsx
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>
);
}
23 changes: 23 additions & 0 deletions docs/src/pages/components/data-grid/rows/DisableSortingGrid.js
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>
);
}
23 changes: 23 additions & 0 deletions docs/src/pages/components/data-grid/rows/DisableSortingGrid.tsx
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>
);
}
Loading

0 comments on commit cde884d

Please sign in to comment.