0
使用角度用戶界面網格http://ui-grid.info/docs/#/tutorial/321_singleFilter,我希望只有一個按鈕來過濾「Company = Mixers」。該過濾器使用輸入工作,但如何將單個過濾器應用於按鈕?使用按鈕的角度用戶界面網格過濾器
Plunker:http://plnkr.co/edit/R6PhMiBbaeqj9ErjdvY1?p=preview
HTML:
<div ng-controller="MainCtrl">
<p><button ng-click='filterBtn()'>Filter for "Company = Mixers"</button></p>
<p><input ng-model='filterValue'/><button ng-click='filter()'>Filter</button></p>
<div id="grid1" ui-grid="gridOptions" class="grid"></div>
</div>
JS:
var app = angular.module('app', ['ngTouch', 'ui.grid']);
app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
var today = new Date();
$scope.gridOptions = {
enableFiltering: false,
onRegisterApi: function(gridApi){
$scope.gridApi = gridApi;
$scope.gridApi.grid.registerRowsProcessor($scope.singleFilter, 200);
},
columnDefs: [
{ field: 'name' },
{ field: 'company' }
]
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
$scope.filterBtn = function(val) {
// filter for "Company = Mixers" only.
$scope.gridApi.grid.dataSource.filter({
field: "company",
operator: "eq",
value: "Mixers" //or val
});
};
$scope.filter = function() {
$scope.gridApi.grid.refresh();
};
$scope.singleFilter = function(renderableRows){
var matcher = new RegExp($scope.filterValue);
renderableRows.forEach(function(row) {
var match = false;
[ 'name', 'company', 'email' ].forEach(function(field){
if (row.entity[field].match(matcher)){
match = true;
}
});
if (!match){
row.visible = false;
}
});
return renderableRows;
};
}]);
http://ui-grid.info/docs/#/tutorial/321_singleFilter:我使用的是Angular UI網格,而不是Kendo。什麼是「運營商」? – simple
對不起,我dindt注意到這個問題關於角網格)我沒有與該網格工作,但谷歌說,做過濾的方式 –
@simple你試試這個嗎? stiil有問題嗎? –