diff --git a/docs/DatagridAG.md b/docs/DatagridAG.md index f2f0aabae8e..37c2eb123c2 100644 --- a/docs/DatagridAG.md +++ b/docs/DatagridAG.md @@ -1734,6 +1734,112 @@ export const PostList = () => { **Tip:** `` registers the following [modules](https://www.ag-grid.com/react-data-grid/modules/) by default: `ClientSideRowModelModule`, `AllCommunityModule` and `CsvExportModule`. If you add other modules, make sure to have at least the `ClientSideRowModelModule`. +### Creating New Records + +There are multiple options to create new records: + +- The simple [`create` view](./Create.md) that redirects users to a dedicated create page: + +```tsx +// in src/posts.tsx +import * as React from 'react'; +import { Create, SimpleForm, TextInput, DateInput, required } from 'react-admin'; +import RichTextInput from 'ra-input-rich-text'; + +export const PostCreate = () => ( + + + + + + + + +); + +// in src/App.tsx +import * as React from 'react'; +import { Admin, Resource } from 'react-admin'; +import jsonServerProvider from 'ra-data-json-server'; + +import { PostCreate, PostList } from './posts'; + +const App = () => ( + + + +); + +export default App; +``` + +- The [`` component from `@react-admin/ra-form-layout`](https://react-admin-ee.marmelab.com/documentation/ra-form-layout#createdialog-editdialog--showdialog) that opens a dialog without leaving the list page: + +```tsx +// In src/posts.tsx +import { List, ListActions, SimpleForm, TextInput, DateInput } from 'react-admin'; +import { DatagridAG } from '@react-admin/ra-datagrid-ag'; +import { CreateDialog } from '@react-admin/ra-form-layout'; + +const columnDefs = [ + { field: 'id', editable: false }, + { field: 'title' }, + { field: 'published_at', headerName: 'Publication Date' }, + { field: 'body' }, +]; + +export const PostList = () => ( + <> + }> + + + + + + + + + + +); +``` + +> **Note**: You can't use the `` and have a standard `` specified on your ``, because the `` declarations would conflict. If you need this, use the `` instead. + +- The [`` component from `@react-admin/ra-form-layout`](https://react-admin-ee.marmelab.com/documentation/ra-form-layout#createdialog-editdialog--showdialog) that opens a dialog without leaving the list page but does not add a `/create` route: + +```tsx +// In src/posts.tsx +import { List, ListActions, SimpleForm, TextInput, DateInput, TopToolbar } from 'react-admin'; +import { DatagridAG } from '@react-admin/ra-datagrid-ag'; +import { CreateInDialogButton } from '@react-admin/ra-form-layout'; + +const columnDefs = [ + { field: 'id', editable: false }, + { field: 'title' }, + { field: 'published_at', headerName: 'Publication Date' }, + { field: 'body' }, +]; + +const PostListActions = () => ( + + + + + + + + + +) + +export const PostList = () => (· + }> + + +); +``` + ## `` `` is an alternative datagrid component with advanced features, based on [ag-grid](https://www.ag-grid.com/). It is designed for small datasets that can be entirely loaded client-side (around a few thousand records). It supports infinite scrolling, grouping, multi-column sorting, and advanced filtering. @@ -3035,3 +3141,109 @@ export const PostList = () => { {% endraw %} **Tip:** `` registers the following [modules](https://www.ag-grid.com/react-data-grid/modules/) by default: `ClientSideRowModelModule`, `AllCommunityModule` and `CsvExportModule`. If you add other modules, make sure to have at least the `ClientSideRowModelModule`. + +### Creating New Records + +There are multiple options to create new records: + +- The simple [`create` view](./Create.md) that redirects users to a dedicated create page: + +```tsx +// in src/posts.tsx +import * as React from 'react'; +import { Create, SimpleForm, TextInput, DateInput, required } from 'react-admin'; +import RichTextInput from 'ra-input-rich-text'; + +export const PostCreate = () => ( + + + + + + + + +); + +// in src/App.tsx +import * as React from 'react'; +import { Admin, Resource } from 'react-admin'; +import jsonServerProvider from 'ra-data-json-server'; + +import { PostCreate, PostList } from './posts'; + +const App = () => ( + + + +); + +export default App; +``` + +- The [`` component from `@react-admin/ra-form-layout`](https://react-admin-ee.marmelab.com/documentation/ra-form-layout#createdialog-editdialog--showdialog) that opens a dialog without leaving the list page: + +```tsx +// In src/posts.tsx +import { List, ListActions, SimpleForm, TextInput, DateInput } from 'react-admin'; +import { DatagridAGClient } from '@react-admin/ra-datagrid-ag'; +import { CreateDialog } from '@react-admin/ra-form-layout'; + +const columnDefs = [ + { field: 'id', editable: false }, + { field: 'title' }, + { field: 'published_at', headerName: 'Publication Date' }, + { field: 'body' }, +]; + +export const PostList = () => ( + <> + } perPage={10000} pagination={false}> + + + + + + + + + + +); +``` + +> **Note**: You can't use the `` and have a standard `` specified on your ``, because the `` declarations would conflict. If you need this, use the `` instead. + +- The [`` component from `@react-admin/ra-form-layout`](https://react-admin-ee.marmelab.com/documentation/ra-form-layout#createdialog-editdialog--showdialog) that opens a dialog without leaving the list page but does not add a `/create` route: + +```tsx +// In src/posts.tsx +import { List, ListActions, SimpleForm, TextInput, DateInput, TopToolbar } from 'react-admin'; +import { DatagridAGClient } from '@react-admin/ra-datagrid-ag'; +import { CreateInDialogButton } from '@react-admin/ra-form-layout'; + +const columnDefs = [ + { field: 'id', editable: false }, + { field: 'title' }, + { field: 'published_at', headerName: 'Publication Date' }, + { field: 'body' }, +]; + +const PostListActions = () => ( + + + + + + + + + +) + +export const PostList = () => (· + } perPage={10000} pagination={false}> + + +); +```