如何过滤我的数据?(ng-grid)

如何过滤我的数据?(ng-grid),第1张

如何过滤我的数据?(ng-grid)

我发现了一种即时更新的方法。基本上,我保留了所有数据的隐藏集,并且在接收到新数据或更改过滤器后-我将此过滤器应用于完整数据集,并将网格交给过滤后的版本。

这使我可以在过滤器中使用 比较器 (即年龄> = 50),这是此问题的目的。

// Full unfiltered data set$scope.entries = []; // Updated and pushed to$scope.gridOptions = {    // The grids already filtered data set    data: 'filteredEntries',    enableColumnResize: false,    multiSelect: false,    enableSorting: false,    selectedItems: $scope.selectedEntries,} $scope.$on("updateEntries", function(data) {     // My table is filled by socket pushes, this is where it is updated.     $scope.updateFilters(); } $scope.$on("newFilter", function(newFilter) {     // This is where I update my filter     $scope.updateFilters(); } $scope.updateFilters = function() {     // Filters the full set and hands the result to the grid.      $scope.filteredEntries = $filter('filter')($scope.entries, $scope.myFilter);     $scope.$digest(); } // A modifiable limit, modify through newFilter so data is refiltered $scope.lowerLimit = 50; // My Filter $scope.myFilter = function(entry) {      if (entry < $scope.lowerLimit) {        return false;      }     return true; }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5651812.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存