Skip to content

Commit

Permalink
try to clarify examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Jul 5, 2022
1 parent eee11d9 commit f4a1f26
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions docs/data/data-grid/row-grouping/row-grouping.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ For instance if you group by `"director"`, you will have two columns titled _Dir
To automatically hide the grouped columns, use the `useKeepGroupedColumnsHidden` utility hook.
The hook will automatically hide the columns when added to the model and show them back when removed from it.

:::warning
This hook is not compatible with the deprecated column property `hide`.

You can manage column visibility with `columnVisibilityModel`, `initialState`, or both together.
To do so, pass them to the hook parameters.
:::

Bellow are two examples about how to use `columnVisibilityModel` or `initialState` with `useKeepGroupedColumnsHidden` hook.
You can mix the two examples to support both at the same time.

```tsx
// Usage with the initial state
const apiRef = useGridApiRef();
Expand Down Expand Up @@ -123,12 +133,6 @@ const [rowGroupingModel, setRowGroupingModel] = React.useState([
const initialState = useKeepGroupedColumnsHidden({
apiRef,
rowGroupingModel,
initialState: {
columns: {
// Other hidden columns
columnVisibilityModel: { gross: false },
},
},
});

return (
Expand All @@ -141,21 +145,6 @@ return (
);
```

:::warning
This hook is not compatible with the deprecated column property `hide`.
It can be used with controlled `columnVisibilityModel` and `initialState`.
To do so, provide the controlled value and the initial state to the hook as follow:

```jsx
const initialState = useKeepGroupedColumnsHidden({
apiRef,
rowGroupingModel,
initialState,
});
```

:::

{{"demo": "RowGroupingUseKeepGroupedColumnsHidden.js", "bg": "inline", "defaultCodeOpen": false}}

## Disable the row grouping
Expand Down

0 comments on commit f4a1f26

Please sign in to comment.