How to implement custom search with smart-table and angularjs
Asked Answered
P

1

10

Is there a way to search a date field with smart-table? I need to filter for dates later then a given date.

Payroll answered 17/11, 2014 at 23:6 Comment(0)
L
16

you can set up a custom (global filter) using the st-set-filter attribute (not documentented yet)

<table st-set-filter="myFilter" st-table="rowCollection">
  ...
</table>

Then implement the custom filter

myApp.filter('myFilter',[function(){
    return function(array, expression){
       //an example
       return array.filter(function(val, index){
           return new Date(val.theDateProperty) > new Date(expression.theDateProperty) ;
       });
    }
});

where for example you have set up you input in the table

<input type="date" st-search="'theDateProperty'" />

Note the filter is global to the table, so it will be called in place of angular filter (the default one used) for very search input. So if you want other filter behaviour for different columns, you'll have to add them in your custom filter, or an other technique is to use a comparator function. You'll find more details in my comment on the pull request (18/11/2014) and a plunker

Edit:

It has been documented in the meanwhile.

Louralourdes answered 18/11, 2014 at 9:12 Comment(1)
- plunker is broken; and is there a way to filter externally from the table DOM? #29262457Scary

© 2022 - 2024 — McMap. All rights reserved.