【问题标题】:react DataGrid: append custom filter operator without erasing the other operatorsreact DataGrid:附加自定义过滤器运算符而不删除其他运算符
【发布时间】:2021-04-08 15:30:35
【问题描述】:

我正在为 React 使用 MaterialUI 的 DataGrid,并且我为其中一列创建了一个自定义过滤器操作符。
我能够将它添加到documentation 中提到的列中,并且工作正常,但是,这删除了其他默认运算符(包含、相等等...)。
我就是这样做的:

columns: GridColDef[] = [
    {
        field: 'myFieldName',
        headerName: 'Column name',
        filterOperators: [MyCustomOperator],// this is the custom operator I have created
    }
]

如何附加我的自定义运算符并保​​留其他运算符?

【问题讨论】:

  • 你找到解决办法了吗?
  • @DeepakBiswal,我必须自己添加所有运算符,并实现每个运算符背后的逻辑。

标签: reactjs datagrid


【解决方案1】:

我尝试使用...getGridStringOperators(),它在所有现有过滤器的末尾添加了新过滤器。因此,对于您的情况,它将如下所示:

columns: GridColDef[] = [
     ...getGridStringOperators(),
     {
        field: 'myFieldName',
        headerName: 'Column name',
        filterOperators: [MyCustomOperator],// this is the custom operator I have created
     }
]

【讨论】:

  • 啊,太好了:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-07
  • 2014-10-12
  • 2018-09-14
  • 2021-12-23
  • 2017-01-09
相关资源
最近更新 更多