简体   繁体   English

自定义过滤器 ag 网格反应

[英]custom filter ag grid react

I was trying to implement a custom DropDown filter in ag grid using React.我试图使用 React 在 ag 网格中实现自定义 DropDown 过滤器。 The link I followed is link我遵循的链接链接

I was able to create the filter, however the filter doesnot appear by default.我能够创建过滤器,但是默认情况下过滤器不会出现。 As a user, we need to click the 3 arrow icon next to the column header and then the filter appears.作为用户,我们需要单击列标题旁边的 3 箭头图标,然后才会出现过滤器。

Is there a way to display the custom filter dropDown by default?有没有办法默认显示自定义过滤器下拉列表?

I hope Floating filters can help you here.我希望Floating filters可以帮助您。

Check this example in ag-grid documentationag-grid 文档中查看此示例

      filter: "agNumberColumnFilter",
      floatingFilterComponent: "sliderFloatingFilter",
      floatingFilterComponentParams: {
        maxValue: 5,
        suppressFilterButton: true
      },

The example shows sliderFloatingFilter , to make it a dropdown filter, I think you need to create custom component for it.该示例显示了sliderFloatingFilter ,要使其成为下拉过滤器,我认为您需要为其创建自定义组件。

Have a look at how team has made TextFloatingFilterComp , DateFloatingFilterComp , NumberFloatingFilterComp etc. on GitHub code看看团队如何在GitHub 代码上制作TextFloatingFilterCompDateFloatingFilterCompNumberFloatingFilterComp

Hope this helps.希望这会有所帮助。

I achieved dropdown/enum filter using this column configuration.我使用此列配置实现了下拉/枚举过滤器。 I my case, I was trying to add a boolean filter.我的情况,我试图添加一个布尔过滤器。

Here is complete example这是完整的例子

https://codesandbox.io/s/ag-grid-react-enum-filter-q4er8?file=/src/App.js:1572-1599 https://codesandbox.io/s/ag-grid-react-enum-filter-q4er8?file=/src/App.js:1572-1599

 const getEnumColumnParams = (enumMap) => { return { cellRenderer: (params) => { if (!params.data) return ""; const { value } = params; return enumMap[value]; }, filterParams: { buttons: ['reset', 'apply'], closeOnApply: true, filterOptions: [ "empty", ...Object.keys(enumMap).map(key => { return { displayKey: key, displayName: enumMap[key], test: function (filterValue, cellValue) { return cellValue === true; }, hideFilterInput: true, }; }) ], suppressAndOrCondition: true, }, }; }; const boolEnum = { true: 'Yes', false: 'No' }; const colorEnum = { '#ff00000': 'Red', '#00ff00': 'Green', '#0000ff': 'Blue', }; const columnDefs = [ { field: 'available', ...getEnumColumnParams(boolEnum), }, { field: 'color', ...getEnumColumnParams(colorEnum), } ];

Or you can create column types and assign type: 'boolColumn' etc in column definition like I did in above codesandbox example或者您可以创建列类型并在列定义中分配type: 'boolColumn'等,就像我在上面的代码和框示例中所做的那样

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

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