如何使用smart-table和angularjs实现自定义搜索

10

有没有一种方法可以在智能表格中搜索日期字段?我需要过滤比给定日期晚的日期。

1个回答

16

你可以使用st-set-filter 属性(尚未记录)设置自定义的(全局筛选器)。

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

然后实现自定义过滤器

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) ;
       });
    }
});

例如,在表格中设置了输入,

<input type="date" st-search="'theDateProperty'" />
请注意,该过滤器对整个表格全局生效,因此将替换每个搜索输入的默认angular过滤器。因此,如果您想要不同列的其他过滤器行为,则需要在自定义过滤器中添加它们,或者另一种技术是使用比较器函数。您可以在我的拉取请求(2014年11月18日)的评论和plunker中找到更多详细信息。 编辑: 同时已经有文档记录了该功能。

1
Plunker 出了问题;有没有一种方法可以从表格 DOM 外部进行过滤?https://dev59.com/qonca4cB1Zd3GeqP5xNz - mg1075

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接