material-ui - XGrid 或 Data Grid:如何在工具栏中限制过滤器运算符?
解决方案
解决方案涉及
getGridStringOperators
使用网格的 api 提供的访问内置的“字符串类型”过滤器使用这些过滤器的引用,继续过滤它们以获得您的 api 支持的内容
最后,使用结果设置列道具。
或者,您可以考虑创建一个自定义道具以在标题中显示您的搜索字段。
下面是代码的样子:
import {
XGrid as DataGrid,
getGridStringOperators,
} from '@material-ui/x-grid';
//-------------------------------------------------------------------------
// Column-related configuration
//
const filterOperators = getGridStringOperators().filter(({ value }) =>
['equals' /* add more over time */ ].includes(value),
);
const columns = [
{ field: 'id', headerName: 'ID', hide: true },
{
field: 'myEqualOnlyField',
className: ['myEqualOnlyField'], // not required
sortable: true, // not required
filterOperators, // <<< required for what you want
flex: 1, // not required
// renderHeader: () => <SearchField />, <<< perhaps useful for a single, equal only option search
},
{
...other fields/columns
},
];
这些文档似乎没有为您想要完成的工作提供明确的示例。尽管如此,这里是相关文档的链接。
最后,为了完善答案,如果您想添加自己的过滤器,即不属于内置过滤器的过滤器,这里有一个链接。
推荐阅读
- artificial-intelligence - Dasha中DSL中的某些字段的目的是什么?
- nlp - 试图分析文本和情绪
- ethereum - 如果我收到 10 Ether 的付款,我想自动发送一些文本(如密钥)
- stripe-payments - 条带捕获电荷不处理
- javascript - 材质 UI 列表组件不显示
- firebase - Firebase 函数 - 部署我的函数后出现 403 Forbidden 错误
- python-3.x - Pandas:比较 2 个数据帧之间相同 Id 的相同列,并创建一个新的数据帧,其中每列的差异
- three.js - Objects look stretched out/distorted only around edges of screen
- python - 打印在快递开始日期后 7 天内交付的所有货件
- python - 在使用 Python 导出之前格式化多个 Excel 文件