Skip to content

Commit

Permalink
[docs] Migrate more pages
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Sep 5, 2020
1 parent 49b50da commit 2572b9f
Show file tree
Hide file tree
Showing 23 changed files with 282 additions and 234 deletions.
5 changes: 2 additions & 3 deletions docs/src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const pages = [
subheader: '/components/foo',
children: [
{ pathname: '/components/data-grid/getting-started' },
{ pathname: '/components/data-grid/selection' },
{ pathname: '/components/data-grid/rendering' },
],
},
Expand Down Expand Up @@ -152,7 +151,7 @@ const pages = [
{ pathname: '/components/data-grid/404', title: '🚧 Data' },
{ pathname: '/components/data-grid/filtering', title: '🚧 Filtering' },
{ pathname: '/components/data-grid/pagination' },
{ pathname: '/components/data-grid/404', title: '🚧 Selection' },
{ pathname: '/components/data-grid/selection' },
{ pathname: '/components/data-grid/editing', title: '🚧 Editing' },
{ pathname: '/components/data-grid/404', title: '🚧 Rendering' },
{ pathname: '/components/data-grid/export', title: '🚧 Export & Import' },
Expand All @@ -170,7 +169,7 @@ const pages = [
{ pathname: '/components/data-grid/rows' },
{ pathname: '/components/data-grid/filtering', title: '🚧 Filtering' },
{ pathname: '/components/data-grid/pagination' },
{ pathname: '/components/data-grid/selection', title: '🚧 Selection' },
{ pathname: '/components/data-grid/selection' },
{ pathname: '/components/data-grid/editing', title: '🚧 Editing' },
{ pathname: '/components/data-grid/rendering', title: '🚧 Rendering' },
{ pathname: '/components/data-grid/export', title: '🚧 Export & Import' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ Use the arrow keys to move the focus.
| <kbd>Shift</kbd> + <kbd>Space</kbd> + <kbd>Arrow Up/Down</kbd> | Select the current row and the row above or below |
| <kbd>CTRL</kbd> + <kbd>A</kbd> | Select all rows |
| <kbd>CTRL</kbd> + <kbd>C</kbd> | Copy the currently selected row |
| <kbd>CTRL</kbd> + Click on cell | Enable multi-selection |

### Sorting

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

### Key assignment conventions

Expand Down
8 changes: 4 additions & 4 deletions docs/src/pages/components/data-grid/pagination/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ The grid exposes a set of methods that enables all of these features using the i

> ⚠️ Only use this API when you have no alternative. Always start from the declarative API that the grid exposes.
- `setPageSize`
- `setPage`
- `onPageChange`
- `onPageSizeChange`
- `setPageSize`: Set the number of rows in one page.
- `setPage`: Set the displayed page.
- `onPageChange`: Callback fired after a new page has been displayed.
- `onPageSizeChange`: Callback fired after the page size was changed.

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

Expand Down
6 changes: 3 additions & 3 deletions docs/src/pages/components/data-grid/rows/rows.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ The grid exposes a set of methods that enables all of these features using the i

> ⚠️ Only use this API when you have no alternative. Always start from the declarative API that the grid exposes.
- `getSortModel`
- `setSortModel`
- `onSortModelChange`
- `getSortModel`: Get the sort model currently applied in the grid.
- `setSortModel`: Set the sort model of the component and trigger a new sorting of rows.
- `onSortModelChange`: Callback fired when the columns sorting changed before the grid has sorted its rows.

### Multi-column sorting ⚡️

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import { DataGrid } from '@material-ui/data-grid';
import { useDemoData } from '@material-ui/x-grid-data-generator';

export default function CheckboxSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid checkboxSelection {...data} />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import { DataGrid } from '@material-ui/data-grid';
import { useDemoData } from '@material-ui/x-grid-data-generator';

export default function CheckboxSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid checkboxSelection {...data} />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import { DataGrid } from '@material-ui/data-grid';
import { useDemoData } from '@material-ui/x-grid-data-generator';

export default function ControlledSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

// TODO /~https://github.com/mui-org/material-ui-x/issues/246
const [, setSelection] = React.useState([]);

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
checkboxSelection
onSelectionChange={(newSelection) => {
setSelection(newSelection.rows);
}}
{...data}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import { DataGrid, RowData } from '@material-ui/data-grid';
import { useDemoData } from '@material-ui/x-grid-data-generator';

export default function ControlledSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

// TODO /~https://github.com/mui-org/material-ui-x/issues/246
const [, setSelection] = React.useState<RowData[]>([]);

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
checkboxSelection
onSelectionChange={(newSelection) => {
setSelection(newSelection.rows);
}}
{...data}
/>
</div>
);
}
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';

export default function DisableClickSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
checkboxSelection
{...data}
columns={data.columns.map((column) => ({
...column,
disableClickEventBubbling: true,
}))}
/>
</div>
);
}
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';

export default function DisableClickSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
checkboxSelection
{...data}
columns={data.columns.map((column) => ({
...column,
disableClickEventBubbling: true,
}))}
/>
</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 MultipleRowSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<XGrid {...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 MultipleRowSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<XGrid {...data} />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import { DataGrid } from '@material-ui/data-grid';
import { useDemoData } from '@material-ui/x-grid-data-generator';

export default function SingleRowSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid {...data} />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import { DataGrid } from '@material-ui/data-grid';
import { useDemoData } from '@material-ui/x-grid-data-generator';

export default function SingleRowSelectionGrid() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid {...data} />
</div>
);
}
43 changes: 42 additions & 1 deletion docs/src/pages/components/data-grid/selection/selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ components: DataGrid, XGrid

# Data Grid - Selection

<p class="description">Selection allows end-users to select and highlight a number of rows that you can then take action on.</p>
<p class="description">Selection allows end-users to select and highlight a number of rows that they can then take action on.</p>

## Row selection

<!--
- https://ag-grid.com/javascript-grid-selection/
- https://ej2.syncfusion.com/react/demos/#/material/grid/selection
- https://ant.design/components/table/#components-table-demo-row-selection
Expand All @@ -20,6 +21,46 @@ components: DataGrid, XGrid
- https://devexpress.github.io/devextreme-reactive/react/grid/docs/guides/selection/
- https://ej2.syncfusion.com/react/demos/#/material/grid/checkbox-selection
- https://demos.telerik.com/kendo-ui/grid/checkbox-selection
-->

Row selection can be performed with a simple mouse click or using the [keyboard shortcuts](/components/data-grid/accessibility/#selection). The grid supports single and multiple rows selection.

### Single row selection

Single row selection is enable by default with the `DataGrid` component.
For the `XGrid`, you need to disable multiple row selection with `disableMultipleSelection={true}`.

{{"demo": "pages/components/data-grid/selection/SingleRowSelectionGrid.js"}}

### Multiple row selection ⚡️

To activate multiple selection, put the focus on the `XGrid` component and maintain the <kbd>CTRL</kbd> key.

{{"demo": "pages/components/data-grid/selection/MultipleRowSelectionGrid.js"}}

## Checkbox selection

To activate checkbox selection set `checkboxSelection={true}`.

{{"demo": "pages/components/data-grid/selection/CheckboxSelectionGrid.js"}}

## Disable selection on click

You might have interactive content in the cells and need to disable the selection of the row on click. Use the `disableClickEventBubbling` option in this case.

{{"demo": "pages/components/data-grid/selection/DisableClickSelectionGrid.js"}}

## Controlled selection

{{"demo": "pages/components/data-grid/selection/ControlledSelectionGrid.js"}}

## apiRef

The grid exposes a set of methods that enables all of these features using the imperative apiRef.

> ⚠️ Only use this API when you have no alternative. Always start from the declarative API that the grid exposes.
- `onSelectionChange`: Callback fired when one or multiple rows get their selection state change.

## 🚧 Range selection ⚡️

Expand Down
11 changes: 9 additions & 2 deletions packages/grid/x-grid-modules/src/hooks/features/useSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const useSelection = (

const selectRows = React.useCallback(
(ids: RowId[], isSelected = true, deSelectOthers = false) => {
if (options.disableMultipleSelection && ids.length > 1) {
if (options.disableMultipleSelection && ids.length > 1 && !options.checkboxSelection) {
throw new Error(
'Material-UI: `disableMultipleSelection` should be false to select more than 1 item.',
);
Expand All @@ -131,7 +131,14 @@ export const useSelection = (
};
apiRef.current.publishEvent(SELECTION_CHANGED, selectionChangeParam);
},
[apiRef, selectedItemsRef, forceUpdate, options.disableMultipleSelection, getSelectedRows],
[
apiRef,
selectedItemsRef,
forceUpdate,
options.disableMultipleSelection,
getSelectedRows,
options.checkboxSelection,
],
);

const rowClickHandler = React.useCallback(
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/x-grid-modules/src/models/api/paginationApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export interface PaginationApi {
*/
setPageSize: (pageSize: number) => void;
/**
* Handler that is triggered after a new page has been displayed
* Callback fired after a new page has been displayed.
* @param handler
*/
onPageChange: (handler: (param: PageChangeParams) => void) => () => void;
/**
* Handler that is triggered after the page size was change
* Callback fired after the page size was changed.
* @param handler
*/
onPageSizeChange: (handler: (param: PageChangeParams) => void) => () => void;
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/x-grid-modules/src/models/api/selectionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export interface SelectionApi {
*/
getSelectedRows: () => RowModel[];
/**
* Handler triggered after a row is selected.
* Callback fired after a row is selected.
* @param handler
*/
onRowSelected: (handler: (param: RowSelectedParams) => void) => () => void;
/**
* Handler triggered after one or multiple rows had a selection state change.
* Callback fired after one or multiple rows had a selection state change.
* @param handler
*/
onSelectionChange: (handler: (param: SelectionChangeParams) => void) => () => void;
Expand Down
Loading

0 comments on commit 2572b9f

Please sign in to comment.