运行时的角度ui-grid设置过滤器 [英] Angular ui-grid Set Filter at Runtime
本文介绍了运行时的角度ui-grid设置过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在运行时通过用户交互设置列过滤器.这是我的尝试:
I'm having trouble setting a column filter at runtime via user interaction. Here's my attempt:
http://plnkr.co/edit/Ynesaq5o3HNsF5r8rXQf?p=preview
$scope.setFilter = function() {
$scope.gridApi.grid.columns[1].filters[0] = {
condition: uiGridConstants.filter.EXACT,
placeholder: '',
term: 'female'
};
$scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
$scope.gridApi.grid.refresh();
}
该字段已设置,并将术语添加到该字段,但数据未刷新.
The field is set and the term is added to the field but the data is not refreshed.
有什么想法吗?
推荐答案
在原始的插件中,我将useExternalFiltering设置为true.删除该问题可以解决我遇到的问题.
In the original plunker I had a useExternalFiltering set to true. Removing that fixed the issue I was having.
var app = angular.module('app', ['ngTouch', 'ui.grid']);
app.controller('MainCtrl', ['$scope', '$http', '$interval', 'uiGridConstants', function ($scope, $http, $interval, uiGridConstants) {
$scope.filterText = 'female';
$scope.gridOptions = {
enableFiltering: false,
columnDefs: [
{ name: 'name', enableFiltering: false },
{ name: 'gender' },
{ name: 'company', enableFiltering: false}
],
onRegisterApi: function( gridApi ) {
$scope.gridApi = gridApi;
}
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
$scope.setFilter = function() {
console.log($scope.gridApi.grid.columns[1]);
$scope.gridApi.grid.columns[1].filters[0] = {
condition: uiGridConstants.filter.STARTS_WITH,
term: $scope.filterText
};
$scope.gridOptions.enableFiltering = true
$scope.gridApi.grid.refresh();
}
}]);
这篇关于运行时的角度ui-grid设置过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文