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;
}
Edit: 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.
This lets me use comparators (i.e. age >= 50) in my filter, which is the purpose of this question.
This is my solution!!
It found with ng-grid in html:
in js:
//JSON
You can use angular to bind to the
filterOptions.filterText
variable. There's a plunker here to demonstrate: http://plnkr.co/edit/PHdBhF?p=previewI'll post the same code below:
The above should be about identical to the plunkers on the docs page.
Notice
ng-model="filterOptions.filterText"
on the<input ...>
. That's all it takes!