使用UI网格进行服务器端过滤

时间:2016-04-19 18:10:26

标签: angularjs user-interface angular-ui-grid

ui grid提供了一个默认过滤,使用netFptions中的enableFiltering:false启用。我没有使用此默认过滤,而是使用在过滤器框中为多列输入的文本,将过滤器发送到serevr并获取数据。我尝试过使用filterOptions但$ scope。$ watch('filterOptions',function(newVal,oldVal){

        if (newVal !== oldVal) {
            $scope.getPagedDataAsync($scope.gridOptions.$gridScope.filterText);
        }
    }, true); 

永远不会被调用。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

有几种不同的方法可以做到这一点。在网格选项的onRegisterApi中,您可以执行以下操作:

  onRegisterApi: function(gridApi) {

         gridApi.core.on.filterChanged($scope,
              function(rowEntity, colDef, newValue, oldValue) {
             // check which filter value changed and do something
             // to get the value from a filter in column X you can do 
                  gridApi.grid.columns[X].filters[0]
              }
         );
  }

您还可以在每个单元格上设置过滤器对象。也许收集您希望过滤的各个列,并在每个单元格上放置一个过滤器对象。每当一个人改变你就会得到你需要的所有值,你就可以在" condition"中创建一个函数。被称为进行过滤。

   filter: { type: xxx, condition: $scope.myCustomFilter }

   $scope.myCustomFilter = function(searchTerm, callValue) {

       // check your various conditions here and return true/false
   }