在智能表上使用自定义条件

Using custom condition on smart-table

本文关键字:自定义 条件 智能      更新时间:2023-09-26

如何向智能表添加自定义搜索条件?

通常,我们将搜索设置为这样的列:

<input st-search="description" placeholder="Description..." type="search"/>

但是,有没有一种方法可以使用自定义功能进行搜索?使用st-set-filter将改变st-search的行为,这不是我想要的。

现在,我在构建这样的表行时添加条件:

<tr ng-repeat="request in r.displayedRequests"
    ng-if="r.isInArray(r.developersList, request.developers && (request.status != 'CAN')">
    <td>{{request.id}}</td>
    <td>{{request.description}}</td>
    <!-- ... -->
</tr>

这样做会过滤正确的行,但这会导致分页失败,因为displayedRequests不会像使用st-search那样更新。

那么,如何使用控制器变量添加条件来过滤表行呢?

(仍然能够在不同的文本输入上使用st-search通过全局或列搜索进行过滤)

这样做会过滤正确的行,但这会使分页失败

在使用ng-repeat时,实际上不应该使用ng-if过滤表行。ng重复表达式可以采用自己的筛选器参数,也可以接受自己的自定义筛选器。

ng-repeat="item in vm.items | filter: thoseIDislike"

这也会扼杀你的分页,所以使用st-safe-src指令来保存数据的安全副本,并通过它重复

样品冲击

但是,有没有一种方法可以使用自定义功能进行搜索?

是的,你可以在input上使用ng-change,当你改变输入的模型值时,函数会运行(为了防止它在每个按键上运行,我使用ng-model-option的去抖动属性)

<input st-search="firstName" 
            placeholder="first name" 
            ng-model="fname" 
            ng-model-options="{ debounce: 1000 }" 
            ng-change="alertMe(fname)">

在控制器中:

$scope.alertMe = function(message) {
  if (message.length>0) {
    alert(message);
  }
}