我正在使用非常好的Smart-table库来显示我的数据。我已经制作了一个自定义的过滤器指令,允许我为按钮分配过滤器,这样用户就可以很容易地按行状态(即“新建”、“完成”、“失败”等)。这可以很好地工作,但我希望能够复合筛选器,这样我就可以根据state列中包含两个值之一的行进行筛选(例如,“New”和“Failed”)。
我的自定义过滤器看起来像....
app.directive('stCustomFilter', function() {
return {
restrict: 'A',
require: '^stTable',
scope: true,
link: function(scope, element, attr, ctrl) {
var tableState = ctrl.tableState();
var searchText = attr.stCustomFilter;
var searchColumn = attr.stCustomFilterColumn;
element.on('click', function(data) {
tableState.search.predicateObject = {};
ctrl.search(searchText, searchColumn);
//console.log(tableState);
scope.$apply();
})
}
};
});并在st-table的标题中使用,如下所示。
<div class="btn-group btn-group-sm">
<button st-custom-filter="" st-custom-filter-column="status">All</button>
<button st-custom-filter="New" st-custom-filter-column="status">New</button>
<button st-custom-filter="Done" st-custom-filter-column="status">Done</button>
<button st-custom-filter="Failed" st-custom-filter-column="status">Failed</button>
</div> 因此,理想情况下,我希望能够通过稍微修改指令在st-custom-filter中使用"New||Failed“之类的东西,但我感觉答案可能在于编写涉及st-pipe方法的更复杂的东西。
有人能提供一两个建议吗?非常感谢。
发布于 2015-03-16 22:37:48
对于默认角度过滤器不支持的OR过滤器,您必须设置一个自定义过滤器,并告诉smart table使用此过滤器来代替默认过滤器
angular.filter('myCustomFilter',function(){
return function(array, predicteObject){
//the predicate object is forwarded by smart table whenever a directive call the search method.. for example :{ myProp1:'myInput1',myProp2:'myInput2
//process the array with your OR logic
}})然后告诉smart table使用您的自定义筛选器来代替默认筛选器
<table st-table="myCollection" st-set-filter="myCustomFilter"></table>发布于 2017-01-28 06:26:13
scope.displayClients = [].concat(scope.clients);
scope.predicates = ['col1', 'col2', 'col3'];
scope.selectedPredicate = scope.predicates[0];
app.filter('myStrictFilter', function($filter){
return function(input, predicate){
return $filter('filter')(input, predicate, false); //false -if contains string, true if matches string
}})
scope.displayClients = [].concat(scope.clients);
scope.predicates = ['col1', 'col2', 'col3'];
scope.selectedPredicate = scope.predicates[0];
app.filter('myStrictFilter', function($filter){
return function(input, predicate){
return $filter('filter')(input, predicate, false); // true for exact match
}})https://stackoverflow.com/questions/28878509
复制相似问题