trNgGrid icon indicating copy to clipboard operation
trNgGrid copied to clipboard

Added a filter-comparator attribute.

Open jantosi opened this issue 10 years ago • 2 comments

Now a different comparator can be specified for each row field. This sets the comparator argument in AngularJS' filter. If this attribute is omitted, the table defaults to a false value -- which means lowercase substring matching. If a function name is given, we will try to resolve it from the local scope and pass it as a comparator.

This is particularly useful when creating your own strict filtering on a field containing similar values (ie. "Field Unit" and "Field Unit Manager"). In the default behaviour, selecting "Field Unit" from a dropdown would match rows with both of the types.

This also allows for some degree of extensibility, allowing users to create their own comparators (think fuzzy-matching!).

jantosi avatar Jul 14 '15 09:07 jantosi

Can you give an example of how this can be implemented?

acd10 avatar Jan 12 '18 07:01 acd10

@acd10 This was some time ago, but having re-read this PR I believe this is how it works:

On each column definition, you can set filterComparator field to true, false, a function name or a function.

  • true means strict matching is enabled for this field
  • false goes back to default behaviour
  • function (or a function name) specifies a comparator function when calling $filter('filter')(itemsFilteredWithComparators, currentPattern, comparator). Useful for custom logic.

jantosi avatar Jan 12 '18 19:01 jantosi