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

[Doc] Update <DatagridAG> doc to use the new package, and document the column order/size persistence #9472

Merged
merged 2 commits into from
Nov 24, 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
86 changes: 76 additions & 10 deletions docs/DatagridAG.md
Original file line number Diff line number Diff line change
@@ -90,16 +90,17 @@ Here are the important things to note:

## Props

| Prop | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `columnDefs` | Required | Array | n/a | The columns definitions |
| `bulkActionButtons` | Optional | Element | `<BulkDelete Button>` | The component used to render the bulk action buttons |
| `cellRenderer` | Optional | String, Function or Element | | Allows to use a custom component to render the cell content |
| `defaultColDef` | Optional | Object | | The default column definition (applied to all columns) |
| `mutationOptions` | Optional | Object | | The mutation options |
| `theme` | Optional | String | `'ag-theme-alpine'` | The name of the ag-grid theme |
| `pagination` | Optional | Boolean | `true` | Enable or disable pagination |
| `sx` | Optional | Object | | The sx prop passed down to the wrapping `<div>` element |
| Prop | Required | Type | Default | Description |
| ------------------- | -------- | --------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------- |
| `columnDefs` | Required | Array | n/a | The columns definitions |
| `bulkActionButtons` | Optional | Element | `<BulkDelete Button>` | The component used to render the bulk action buttons |
| `cellRenderer` | Optional | String, Function or Element | | Allows to use a custom component to render the cell content |
| `defaultColDef` | Optional | Object | | The default column definition (applied to all columns) |
| `mutationOptions` | Optional | Object | | The mutation options |
| `preferenceKey` | Optional | String or `false` | `${resource}.ag-grid.params` | The key used to persist columns order and sizing in the Store. `false` disables persistence. |
| `sx` | Optional | Object | | The sx prop passed down to the wrapping `<div>` element |
| `theme` | Optional | String | `'ag-theme-alpine'` | The name of the ag-grid theme |
| `pagination` | Optional | Boolean | `true` | Enable or disable pagination |

`<DatagridAG>` also accepts the same props as [`<AgGridReact>`](https://www.ag-grid.com/react-data-grid/grid-options/) with the exception of `rowData`, since the data is fetched from the List context.

@@ -336,6 +337,49 @@ export const PostList = () => {

{% endraw %}

This also allows to display a notification after the mutation succeeds.

{% raw %}

```tsx
import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-alpine.css';
import React from 'react';
import { List, useNotify } from 'react-admin';
import { DatagridAG } from '@react-admin/ra-editable-datagrid';

export const PostList = () => {
const columnDefs = [
{ field: 'title' },
{ field: 'published_at' },
{ field: 'body' },
];
const notify = useNotify();
const onSuccess = React.useCallback(() => {
notify('ra.notification.updated', {
type: 'info',
messageArgs: {
smart_count: 1,
},
undoable: true,
});
}, [notify]);
return (
<List perPage={10000} pagination={false}>
<DatagridAG
columnDefs={columnDefs}
mutationOptions={{
mutationMode: 'undoable',
onSuccess,
}}
/>
</List>
);
};
```

{% endraw %}

## `theme`

You can use a different theme for the grid by passing a `theme` prop. You can for instance use one of the [themes provided by ag-grid](https://www.ag-grid.com/react-data-grid/themes/), like `ag-theme-balham` or `ag-theme-alpine-dark`:
@@ -405,6 +449,28 @@ const CarList = () => {
Your browser does not support the video tag.
</video>

### `preferenceKey`

`<DatagridAG>` will store the order and size of columns in the [Store](./Store.md), under the key `${resource}.ag-grid.params`.

If you wish to change the key used to store the columns order and size, you can pass a `preferenceKey` prop to `<DatagridAG>`.

```tsx
<List perPage={10000} pagination={false}>
<DatagridAG columnDefs={columnDefs} preferenceKey="my-post-list" />
</List>
```

If, instead, you want to disable the persistence of the columns order and size, you can pass `false` to the `preferenceKey` prop:

```tsx
<List perPage={10000} pagination={false}>
<DatagridAG columnDefs={columnDefs} preferenceKey={false} />
</List>
```

**Note:** Saving the columns size in the Store is disabled when using the [`flex` config](https://www.ag-grid.com/react-data-grid/column-sizing/#column-flex).

## `sx`

You can also use [the `sx` prop](./SX.md) to customize the grid's style: