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.
columnDefs = [
{
headerName: 'Id', field: 'id', sort: 'asc', sortable: true, filter: true,
checkboxSelection: true, resizable: true,
},
{
headerName: 'Name', field: 'name', sortable: true, filter: true,
checkboxSelection: false, editable: true, resizable: true,
},
{
headerName: 'Description', field: 'description', sortable: true, filter: true,
checkboxSelection: false, editable: true, resizable: true,
},
];
Thank you for any possible given help.
This is how i have implement the solution by ##wentjun##:
constructor(private dialog: MatDialog, private adminService: AdminService) {}
columnDefs = [
{
headerName: 'Id', field: 'id', sortable: true, filter: true,
checkboxSelection: true, resizable: true,
},
{
headerName: 'Name', field: 'name', sortable: true, filter: true,
checkboxSelection: false, editable: true, resizable: true,
comparator: this.customComparator,
},
{
headerName: 'Description', field: 'description', sortable: true, filter: true,
checkboxSelection: false, editable: true, resizable: true,
},
];
customComparator(valueA, valueB) {
return valueA.toLowerCase().localeCompare(valueB.toLowerCase());
}
Easiest way is to override the default css header template used by ag-grid. You'll note that i have removed the span tag "eSortOrder" in my template code. Apply same approach to other column for whom you want to remove sort order reference. Handle to css template also gives you power to manipulate the header display.
Sorting is made available very easy in Ag-Grid. All you have to do is add a property sortable: true in column defination. Default sorts: If you are wishing to have to default sorting order, then add sortingOrder:['desc'] which will give you default descending sorting order.
Enable filtering by setting grid property enableFilter=true. This turns on filtering on all columns. To turn off filtering for particular columns, set suppressFilter=true on the individual column definition.
Enable Sorting Turn sorting on for the grid by enabling sorting in the grid options. Sort a column by clicking on the column header. To do multi-column sorting, hold down shift while clicking the column header.
Note that by now you can just set the accentedSort
property in the GridOptions
to true
to achieve case-insensitive sorting. See here for more information.
If you use the custom comparator solution from wentjun please make sure to only apply it to string columns or, when applying to all columns, check if the value is a string. Otherwise the sorting won't work anymore on number based columns:
const customLowerCaseComparator = (valueA, valueB) => {
if (typeof valueA === 'string') {
return valueA.toLowerCase().localeCompare(valueB.toLowerCase());
}
return (valueA > valueB? 1 : (valueA < valueB ? -1 : 0));
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With