esvit / ng-table

Simple table with sorting and filtering on AngularJS
http://esvit.github.io/ng-table
BSD 3-Clause "New" or "Revised" License
2.77k stars 851 forks source link

Custom filter comparator for column #861

Open stepanets opened 8 years ago

stepanets commented 8 years ago

It would be grate to have opportunity to define custom filter comparator or function by column. Like here but not for whole table.

phazei commented 7 years ago

This would make the filters so much more versatile. Currently if you have a dozen columns, but only one is custom, you still have to write cases for all 12 columns :(

kiren-aur commented 7 years ago

+1 @stepanets Depends on how you imagine the configuration @phazei, right? Imagine attributing the customComparator for a column name like this (with an optional 2nd argument) : $scope.tableParams.filter({ name : searchText }, customComparator) and that if we don't specify this 2nd argument the filterComparator will be considered undefined (= default filter).

But for that we would also need to redefine the structure of filterOptions . Maybe like this - with a configuration for each column (with, as I said, by default, filterComparator: undefined when it's not specified so no need to write each column case) :

filterOptions: { 
  column1 : {
    filterComparator: undefined, 
    .
    .
  },
  column2 : {
    filterComparator: customComparator, 
    .
    .
  }, { ... }
}

Which means that the customComparator will be used only when filtering column2 data.

(hope this is not a dumb idea.. I am currently confronted with the problem and this came to my mind)