我在运行时通过用户交互设置列过滤器时遇到问题。这是我的尝试:
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();
}
该字段已设置且该字词已添加到字段中,但数据未刷新。
有什么想法吗?
答案 0 :(得分:2)
在原始的plunker中,我将useExternalFiltering设置为true。删除它解决了我遇到的问题。
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();
}
}]);