How to make sorting key insensitive in ag-grid?

后端 未结 2 1835
忘了有多久
忘了有多久 2020-12-10 17:03

I am working in some grids and I notice that the sorting on all of them is key sensitive is there any way to change that. This is a part of my code.

 columnD         


        
相关标签:
2条回答
  • 2020-12-10 17:16

    This can be done by using a custom sorting function on the particular column that requires case-insensitive sorting.

    For instance, for your columnDefs, if you require the name column to be sorted case insentitve, we pass the customComparator as the value for the comparator property. In your ngOnInit,

    this.columnDefs = [
      {
        headerName: 'Name',
        field: 'name',
        sort: 'asc',  // optional, allows grid column to be sorted on init
        comparator: customComparator
      },
      // other columns
    ];
    

    Then, we define the customComparator such that it carries out case-insentitive sorting. We do so by converting the values to lowercase on the custom comparator.

    const customComparator = (valueA, valueB) => {
      return valueA.toLowerCase().localeCompare(valueB.toLowerCase());
    };
    

    EDIT: I have forked and recreated a demo from the original ag-grid demo to demonstrate the usage of the above comparator. Refer to the constructor() method for the relevant details.

    0 讨论(0)
  • 2020-12-10 17:24

    Update for 2020-07, agTextColumnFilter that is the default ag-Grid filter, accepts parameters. One of which is caseSensitive. See sample

    0 讨论(0)
提交回复
热议问题