Angular ui-grid 在运行时设置过滤器 [英] Angular ui-grid Set Filter at Runtime

查看:28
本文介绍了Angular 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.

有什么想法吗?

推荐答案

在最初的 plunker 中,我将 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(); 
  }

}]);

这篇关于Angular ui-grid 在运行时设置过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆