智能表的角过滤器不更新页面

Smart Table angular filter not updating the page

本文关键字:更新 过滤器 智能      更新时间:2023-09-26

我创建了这个活塞

https://plnkr.co/edit/zrSgAG3NctuveLTNgnZS?p=preview

你可以看到有一个全局搜索,你可以搜索或点击类别,如eyeColor或性别,按类别过滤。滤镜效果很好。但是页脚上的页面不能正确反映数据。尽管过滤器没有缩小数据集,但页面计数不会改变。我没有使用st-filter,因为我需要支持点击和过滤,例如眼睛的颜色和性别,你可以点击你想要过滤的类别。

I am using searcQuery filter this way instead
      <input type="search" ng-model="vm.searchQuery" placeholder="Global search" class="input-sm form-control" />
.
.
.
    ng-repeat-start="artists in (displayedCollection | filter: vm.searchQuery)">

你知道我做错了什么吗?

必须直接调用表API .search()函数。默认情况下,smart-table是单向的,不需要ngModel(以避免复杂的双向状态同步)。如果你想这样做,我建议你把你的行为包装在一个指令中,观察模型变化并调用表api

app.directive('filter',function(){
    return {
        require:'stTable',
        scope:{
            filter:'='
        },
        link:function(scope,el,att,table){
                scope.$watch('filter',function(val){
                    table.search(val);
                });
        }
    }
})

恰好