How to implement custom search with smart-table and angularjs

user2543492 picture user2543492 · Nov 18, 2014 · Viewed 17.1k times · Source

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

Answer

laurent picture laurent · Nov 18, 2014

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.