Briefly: Is there any way to implement a custom comparator for the number column filters?
Long story:
I use ag-grid in Angular (2). I provide my own components for cells in my ag-grid:
let column = {
headerName: column.header,
field: column.id,
cellRendererFramework: DynamicComponent,
filter: this.convertFormatToFilterType(column.format) // returns "text", "number" or "date"
}
In order to make the filters get values from my cells properly I provide custom comparators (this one is for the text column filters):
if (c.filter === "text")
c['filterParams'] = {
textCustomComparator: (filter, cell, filterText): boolean => {
var filterTextLowerCase = filterText.toLowerCase();
var valueLowerCase = cell.value.toString().toLowerCase();
switch (filter) {
case 'contains':
return valueLowerCase.indexOf(filterTextLowerCase) >= 0;
case 'notContains':
return valueLowerCase.indexOf(filterTextLowerCase) === -1;
case 'equals':
return valueLowerCase === filterTextLowerCase;
case 'notEqual':
return valueLowerCase != filterTextLowerCase;
case 'startsWith':
return valueLowerCase.indexOf(filterTextLowerCase) === 0;
case 'endsWith':
var index = valueLowerCase.lastIndexOf(filterTextLowerCase);
return index >= 0 && index === (valueLowerCase.length - filterTextLowerCase.length);
default:
// should never happen
console.warn('invalid filter type ' + filter);
return false;
}
}
};
You can see I need to access the value of the cell by using "cell.value". The code above works fine.
What I have troubles with is providing similar functionality for the number column filters - they don't seem to use any custom comparator. Therefore, what is happening, the filter tries to access the cell's value directly instead of using "cell.value".
So, is there any way to implement a custom comparator for the number column filters? Or, if not, any other way I can get the value from my cells correctly in this case?