最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ag-Grid 'agSetColumnFilter' Customization - Stack Overflow

programmeradmin2浏览0评论

Can i change the default behaviour of agSetColumnFilter of ag-grid. I can change the filter values by using values: paramter in filterParams. But Since Set Filter performs exact serarch with cell Value so can i update it to Contains search instead of Exact Search.

Can i change the default behaviour of agSetColumnFilter of ag-grid. I can change the filter values by using values: paramter in filterParams. But Since Set Filter performs exact serarch with cell Value so can i update it to Contains search instead of Exact Search.

Share Improve this question edited Feb 26, 2024 at 15:35 KARTHIKEYAN.A 20.2k10 gold badges137 silver badges150 bronze badges asked Dec 6, 2019 at 10:38 Shubham RastogiShubham Rastogi 561 gold badge1 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

Yes, you can do it. Under column definition.

{
filter: 'agSetColumnFilter',
filterParams: { 
    values: ["custom1", "custom2"] 
}

Also read about [https://www.ag-grid./javascript-grid-server-side-model-filtering/#example-set-filter] to load the values Async.

No, that's not supported. The whole point of the agSetColumnFilter is to match a (hopefully) small set of values contained in a column. If you have so many different values that you need a 'contains' filter, then the setFilter is probably not appropriate anyway.

That said, if you want custom behavior in a filter, that is not acmodated by a standard filter your best is probably to write your own custom filter. The documentation for custom filters can be found at https://www.ag-grid./javascript-grid-filter-ponent/#custom-filter-example

Apply List of Key words to setfilter model in the following way

Column Definition:

const [columnDefs, setColumnDefs] = useState([
    // explicitly configure column to use the Set Filter
    { field: 'entityStatus.code', filter: 'agSetColumnFilter' },
]);

Custom Filter:

useEffect(() => {
    if (gridAPI) {
        const model = gridAPI.api.getFilterModel() // get previous filter model
        const currentModel = {
            'entityStatus.code': {
                filterType: 'set',
                values: selectedStatus // [ '104' , '503' ]
            }
        }
        const updatedModel = {
            ...model,
            ...currentModel
        }

        if (!isEmpty(selectedStatus)) {
            gridAPI.api.setFilterModel(updatedModel) // apply filter
        } else {
            gridAPI.api.destroyFilter('entityStatus.code') // destroy applied filter in perticular column 
        }
    }
}, [ selectedStatus ])
发布评论

评论列表(0)

  1. 暂无评论