Skip to content

Commit 0c7d80a

Browse files
committed
Adding Search And Filters To The List
1 parent 52be3f6 commit 0c7d80a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Customize the Edit view title with a title component instead of the id
1+
// Added Search And Filters To The List
22
// https://marmelab.com/react-admin/Tutorial.html
33

44
import React from 'react';

src/posts.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import React from 'react';
2-
import { List, Datagrid, TextField, ReferenceField, EditButton, Edit, SimpleForm, ReferenceInput, SelectInput, TextInput, DisabledInput, LongTextInput, Create } from 'react-admin';
2+
import { Filter, List, Datagrid, TextField, ReferenceField, EditButton, Edit, SimpleForm, ReferenceInput, SelectInput, TextInput, DisabledInput, LongTextInput, Create } from 'react-admin';
33

44
const PostTitle = ({ record }) => {
55
return <span>Post {record ? `"${record.title}"` : ''}</span>
66
}
77

8+
const PostFilter = (props) => (
9+
<Filter {...props}>
10+
<TextInput label="Search" source="q" alwaysOn />
11+
<ReferenceInput label="User" source="userId" reference="users" allowEmpty>
12+
<SelectInput optionText="name" />
13+
</ReferenceInput>
14+
</Filter>
15+
)
16+
817
export const PostList = props => (
9-
<List {...props}>
18+
<List {...props} filters={<PostFilter />}>
1019
<Datagrid>
1120
<TextField source="id" />
1221
<ReferenceField source="userId" reference="users">

0 commit comments

Comments
 (0)