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



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

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

永远不会被调用。任何帮助都将不胜感激。

有几种不同的方法可以做到这一点。在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]
              }
         );
  }

您也可以在每个单元格上设置一个过滤器对象。也许可以收集要筛选的各个列,并在每个单元格上放置一个筛选对象。无论何时发生更改,您都将拥有所需的所有值,并且您可以在"条件"中创建一个函数,该函数将被调用来执行flering。

   filter: { type: xxx, condition: $scope.myCustomFilter }
   $scope.myCustomFilter = function(searchTerm, callValue) {
       // check your various conditions here and return true/false
   }

最新更新