Skip to content

Commit cfbfb1d

Browse files
authored
Merge pull request #10800 from marmelab/docs-datatable-hiddencolumns
Add docs about `<DataTable hiddenColumns>`
2 parents f12ed7c + 42d81e4 commit cfbfb1d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/DataTable.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,33 @@ const PostList = () => (
693693

694694
**Tip**: To handle sorting in your custom DataTable head component, check out the [Building a custom sort control](./ListTutorial.md#building-a-custom-sort-control) section.
695695

696+
## `hiddenColumns`
697+
698+
By default, `<DataTable>` renders all `<DataTable.Col>` children. Use the `hiddenColumns` property to set hidden columns by default.
699+
700+
```tsx
701+
import { ColumnsButton, TopToolbar, List, DataTable } from 'react-admin';
702+
703+
const PostListActions = () => (
704+
<TopToolbar>
705+
<ColumnsButton />
706+
</TopToolbar>
707+
)
708+
709+
const PostList = () => (
710+
<List actions={<PostListActions />}>
711+
<DataTable hiddenColumns={['id', 'author']}>
712+
<DataTable.Col source="id" />
713+
<DataTable.Col source="title" />
714+
<DataTable.Col source="author" />
715+
<DataTable.Col source="year" />
716+
</DataTable>
717+
</List>
718+
);
719+
```
720+
721+
Using the `hiddenColumns` property instead of removing `<DataTable.Col>` elements entirely allows hidden columns to be displayed again using a `ColumnsButton`, as explained in the [Hiding or Reordering Columns](#hiding-or-reordering-columns) section.
722+
696723
## `hover`
697724

698725
By default, when a user hovers over a row, the background color changes to indicate the row is active. Set the `hover` prop to `false` to disable this behavior.

0 commit comments

Comments
 (0)