How to make sorting key insensitive in ag-grid?

扶醉桌前 提交于 2019-11-29 16:45:06

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!