Skip to content

Commit ee7466a

Browse files
authored
Merge pull request #8901 from WiXSL/docs-datagrid-isrowselectable
Update Datagrid's `isRowSelectable` description and examples
2 parents 93e0f34 + b23b732 commit ee7466a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

docs/Datagrid.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Additional props are passed down to [the Material UI `<Table>` element](https://
6262

6363
By default, `<Datagrid>` renders its body using `<DatagridBody>`, an internal react-admin component. You can pass a custom component as the `body` prop to override that default. And by the way, `<DatagridBody>` has a `row` prop set to `<DatagridRow>` by default for the same purpose. `<DatagridRow>` receives the row `record`, the `resource`, and a copy of the `<Datagrid>` children. That means you can create custom `<Datagrid>` logic without copying several components from the react-admin source.
6464

65-
For instance, the `<Datagrid isRowSelectable>` prop allows to hide the selection checkbox for some records. To show a *disabled* checkbox instead of hiding it, you can override `<DatagridRow>` and `<DatagridBody>` as follows:
65+
For instance, the `<Datagrid isRowSelectable>` prop allows to disable the selection checkbox for some records. To *hide* checkboxes instead of disabling them, you can override `<DatagridRow>` and `<DatagridBody>` as follows:
6666

6767
```jsx
6868
// in src/PostList.js
@@ -74,12 +74,13 @@ const MyDatagridRow = ({ record, id, onToggleItem, children, selected, selectabl
7474
<TableRow>
7575
{/* first column: selection checkbox */}
7676
<TableCell padding="none">
77-
<Checkbox
78-
disabled={selectable}
79-
checked={selected}
80-
onClick={event => onToggleItem(id, event)}
81-
/>
82-
</TableCell>
77+
{selectable && (
78+
<Checkbox
79+
checked={selected}
80+
onClick={event => onToggleItem(id, event)}
81+
/>
82+
)}
83+
</TableCell>
8384
{/* data columns based on children */}
8485
{React.Children.map(children, field => (
8586
<TableCell key={`${id}-${field.props.source}`}>
@@ -581,9 +582,9 @@ const PostList = () => (
581582

582583
## `isRowSelectable`
583584

584-
You can customize which rows show a selection checkbox using the `isRowSelectable` prop. It expects a function that receives the row record and returns a boolean.
585+
You can customize which rows show an enabled selection checkbox using the `isRowSelectable` prop. It expects a function that receives the row record and returns a boolean.
585586

586-
For instance, this code shows a checkbox only for rows with an id greater than 300:
587+
For instance, this code enables a checkbox only for rows with an id greater than 300:
587588

588589
```jsx
589590
import { List, Datagrid } from 'react-admin';

0 commit comments

Comments
 (0)