如何过滤我的数据? (NG-网格) [英] How to filter my data? (ng-grid)
问题描述
我觉得这是最有可能很简单,但我无法找到如何添加一个在其网站上显示的filterText之外的过滤任何明确的文档。我所试图做的是简单的东西,因为这:
I think this is most likely very simple but I cannot find any clear documentation on how to add a filter outside of the 'filterText' that is shown on their website. What I am trying to do is something as simple as this:
$scope.filterOptions = {
filter: $scope.myFilter, // <- How to do something like this?
useExternalFilter: true
}
$scope.gridOptions = {
data: 'entries',
enableColumnResize: false,
multiSelect: false,
enableSorting: false,
selectedItems: $scope.selectedEntries,
filterOptions: $scope.filterOptions
}
$scope.lowerLimit = 50;
// My Filter
$scope.myFilter = function(entry) {
if (entry < $scope.lowerLimit) {
return false;
}
return true;
}
编辑:或者,也许,如果我能以某种方式过滤数据源?我想这样的:
Or maybe if I could filter the datasource somehow? I tried this:
$scope.gridOptions = {
data: 'entries | filter: myFilter',
enableColumnResize: false,
multiSelect: false,
enableSorting: false,
selectedItems: $scope.selectedEntries,
}
但它扔了不少错误。
But it is throwing quite a few errors.
推荐答案
我发现,会立即更新的方式。基本上我认为一个隐藏的设置我的所有数据,并在接收新数据或改变我的过滤器 - 我将此过滤器应用于完整的数据集和手电网的过滤版本。
I have found a way that updates instantly. Basically I hold a hidden set of all my data, and upon receiving new data or changing my filter - I apply this filter to the full data set and hand the grid the filtered version.
这让我在我的过滤器,这是这个问题的目的,使用的比较的(即年龄> = 50)。
This lets me use comparators (i.e. age >= 50) in my filter, which is the purpose of this question.
// 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;
}
这篇关于如何过滤我的数据? (NG-网格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!