Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix <Datagrid> rowClick type and documentation #8677

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/Datagrid.md
Original file line number Diff line number Diff line change
@@ -655,9 +655,10 @@ export const PostList = () => (
* "show" to redirect to the show vue
* "expand" to open the `expand` panel
* "toggleSelection" to trigger the `onToggleItem` function
* a function `(id, resource, record) => path` to redirect to a custom path
* `false` to do nothing
* a function `(id, resource, record) => path` that may return any of the above values or a custom path

**Tip**: If you pass a function, it can return `edit`, `show`; or a router path. This allows to redirect to either `edit` or `show` after checking a condition on the record. For example:
**Tip**: If you pass a function, it can return `edit`, `show`; `false` or a router path. This allows to redirect to either `edit` or `show` after checking a condition on the record. For example:

```js
const postRowClick = (id, resource, record) => record.editable ? 'edit' : 'show';
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/list/datagrid/Datagrid.tsx
Original file line number Diff line number Diff line change
@@ -337,7 +337,7 @@ export interface DatagridProps<RecordType extends RaRecord = any>
isRowSelectable?: (record: RecordType) => boolean;
isRowExpandable?: (record: RecordType) => boolean;
optimized?: boolean;
rowClick?: string | RowClickFunction;
rowClick?: string | RowClickFunction | false;
rowStyle?: (record: RecordType, index: number) => any;
size?: 'medium' | 'small';
// can be injected when using the component without context
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ export interface DatagridBodyProps extends Omit<TableBodyProps, 'classes'> {
record?: RaRecord;
resource?: string;
row?: ReactElement;
rowClick?: string | RowClickFunction;
rowClick?: string | RowClickFunction | false;
rowStyle?: (record: RaRecord, index: number) => any;
selectedIds?: Identifier[];
isRowSelectable?: (record: RaRecord) => boolean;