简体   繁体   English

为 react-admin 列表视图添加自定义过滤器下拉列表

[英]Add a custom filter drop down for react-admin List view

Question 1: I have a list view with a column for "Active":问题 1:我有一个包含“活动”列的列表视图:

在此处输入图像描述

I want to allow the user to select Active/Inactive from a radio button group as a filter (or dropdown).我想允许用户从单选按钮组中将 select Active/Inactive 作为过滤器(或下拉菜单)。 I know react-admin provides filters for reference fields out of the box.我知道 react-admin 为参考字段提供了开箱即用的过滤器。 What about a non-reference field, like "Active"?像“Active”这样的非参考字段呢?

Question 2: Any way to add a clear button or "X" by the search field to quickly clear all filters?问题2:有什么方法可以在搜索栏添加清除按钮或“X”来快速清除所有过滤器? Currently, you have to select what's in Search and clear the text.目前,您必须 select 搜索中的内容并清除文本。 Annoying having to use the mouse AND keyboard to clear filters.烦人的必须使用鼠标和键盘来清除过滤器。 But, I'm guessing there's a way around it.但是,我猜有办法解决它。

Thanks.谢谢。

I want to allow the user to select Active/Inactive from a radio button group as a filter (or dropdown).我想允许用户从单选按钮组中将 select Active/Inactive 作为过滤器(或下拉菜单)。 I know react-admin provides filters for reference fields out of the box.我知道 react-admin 为参考字段提供了开箱即用的过滤器。 What about a non-reference field, like "Active"?像“Active”这样的非参考字段呢?

There is BooleanInput and NullableBooleanInput .BooleanInput 和 NullableBooleanInput Documentation is quite well written and there are lots of Input components to use.文档写得很好,有很多输入组件可供使用。

Question 2: Any way to add a clear button or "X" by the search field to quickly clear all filters?问题2:有什么方法可以在搜索栏添加清除按钮或“X”来快速清除所有过滤器? Currently, you have to select what's in Search and clear the text.目前,您必须 select 搜索中的内容并清除文本。 Annoying having to use the mouse AND keyboard to clear filters.烦人的必须使用鼠标和键盘来清除过滤器。 But, I'm guessing there's a way around it.但是,我猜有办法解决它。

if you are using TextInput for search field there is prop resettable如果您将TextInput用于搜索字段,则resettable道具

With those two things combined you should have more or less similar code in filter component:将这两件事结合起来,您应该在过滤器组件中有或多或少相似的代码:

<Filter {...props}>
   <TextInput label="Search" source="q" alwaysOn resettable />
   <NullableBooleanInput label="Is Active" source="active" alwaysOn/>
</Filter>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM