0

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.

Any ideas?

1 Answer 1

2

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(); 
  }

}]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.