Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS : Update filter for UI Grid from external method

I would like to be able to set/update a value in my controller that is then filtered in the grid. Currently, the changes to the filter aren't updated until I type into the grid which then triggers the filterChanged event. Any idea of how I can automatically filter the data in my grid config or at least do a hard refresh?

Thank you for the help.

Here's a slightly modified Plunker from the AngularJS UI Grid website. http://plnkr.co/edit/pgX31NT3Ry3XllZ3JO2B?p=preview

Here's my current filter definition in the columnDefs section:

    { field: 'company', filter: {
    noTerm: true,
    condition: function(searchTerm, cellValue) {
      return cellValue == scope.term;
    }
like image 905
neonScarecrow Avatar asked Sep 29 '22 19:09

neonScarecrow


1 Answers

When you define your gridOptions, set the gridAPI variable with the following:

onRegisterApi: function(gridApi){
    $scope.gridApi = gridApi;
},

And then in your update function, run the following to re-evaluate the filter condition:

$scope.gridApi.grid.refresh()

As @Conan mentioned, a breaking update was released and this works only in

There was a bug and this doesn't work on 3.2.x. Tested and works in 3.1.x and 4.x http://plnkr.co/edit/YbgV9YZrWCZE4cc3qGru?p=preview

like image 172
r0m4n Avatar answered Oct 05 '22 07:10

r0m4n