为角度UI网格实现外部过滤器的便捷方法是什么



在第50行的源代码中,它说:

/**
           * @ngdoc event
           * @name filterChanged
           * @eventOf  ui.grid.core.api:PublicApi
           * @description  is raised after the filter is changed.  The nature
           * of the watch expression doesn't allow notification of what changed,
           * so the receiver of this event will need to re-extract the filter 
           * conditions from the columns.
           * 
           */
          this.registerEvent( 'core', 'filterChanged' );

就我而言,我people table有三列,分别是NameSurnameEmail。我可以处理过滤器更改:

vm1.gridApi.core.on.filterChanged($scope, function () {
....
}

发送我的所有参数服务器端并在所有字段中搜索。

这可能适用于少数列。见普伦克

对于巨大的桌子,在客户端处理什么方便的方式?

在@PaulL的回答的帮助下,我得出了这个解决方案:

vm.gridApi.core.on.filterChanged($scope, function () {
    var grid = vm.gridApi.grid;
    var filters = [];
    vm.gridApi.grid.columns.forEach(function (column) {
        if (column.filters && column.filters[0].term) {
            filters[column.name] = column.filters[0].term;
        };
    });
    console.log(filters);
    service.getEntries(filters, paginationOptions.pageNumber, paginationOptions.pageSize, paginationOptions.sortDir).
    then(function (result) {
        vm.gridOptions.data = result.data.value;
    })
});

通常我只会使用以下方法提取它们:

var filters = [];
$scope.gridApi.grid.columns.forEach( function(column) {
  if( column.filters && column.filters.length > 0 ) {
    filters.push({name: column.name, filters: column.filters});
  };
});

然后,您可以在发送到服务器之前根据需要处理这些筛选器。 我通常也会对过滤器进行去抖动,您不想每次按键都调用服务器。

相关内容

最新更新