Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement custom search with smart-table and angularjs

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

like image 910
user2543492 Avatar asked Nov 17 '14 23:11

user2543492


1 Answers

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.

like image 159
laurent Avatar answered Sep 20 '22 14:09

laurent