How to reset filter values in react admin framework?
·
Answer a question
I have a filter component:
export const PostsFilter = (props) => (
<Filter {...props}>
<TextInput label='Post ID' source='id' alwaysOn />
<TextInput label='User ID' source='user_id' alwaysOn />
</Filter>
);
I need to add a reset button that will clear input values. I understand that in should be done via dispatching smth to redux. So maybe somebody already solved this problem? Thanks!
Answers
There is a setFilters prop in your filter component, you can use it:
export const PostsFilter = (props) => (
<div>
<Filter {...props}>
<TextInput label='Post ID' source='id' alwaysOn />
<TextInput label='User ID' source='user_id' alwaysOn />
</Filter>
<Button onClick={() => props.setFilters({
id: '',
user_id: ''
})}>Clear fields</Button>
<div>
);
更多推荐
所有评论(0)