Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ui-grid set filter field programatically and refresh. Value not showing up

I have a ui-grid with a bunch of columns using the built in filtering. One of the columns is "owner". There is a button you can click that says "My Items". When clicked that button should populate the Owner Filter field with the users name and filter the items. I am setting the filter as follows as specified in the ui-grid documentation:

$scope.gridApi.grid.columns[3].filters[0] = "somename";

However "somename" never shows up in the column filter header, and the data never refreshes. I've tried calling refresh() as well as notifyDataChange but nothing seems to work.

Thanks.

like image 484
Scott Avatar asked Nov 05 '15 02:11

Scott


2 Answers

Here is the correct way of doing it. By the way, there is no need to call refresh() function.

  $scope.gridApi.grid.columns[3].filters[0] = {
    term: somename
  };
like image 97
SaiGiridhar Avatar answered Nov 14 '22 21:11

SaiGiridhar


I was trying to work this answer, but was having problems. I solved it with a slight syntax alteration (changed grids.columns[2] to grid.getColumn('mycolumn') )

$scope.grid1Api.grid.getColumn('speicialty').filters[0] = {
   term: whatever
};

Hope that helps for anyone looking

For my particular case, this is all of my code:

Controller:

function skillsFunc(job) {
   console.log(job);
   $scope.grid1Api.grid.getColumn('speicialty').filters[0] = {
      term: job
   };
};

HTML:

<div class="input-field col s2 locator-margin3">
  <label for="skills1" class="locator-label">SPECIAL SKILLS</label>
  <select ng-model="vm.skills" ng-change="vm.skillsFunc(vm.skills)" id="skills1" class="browser-default locator-select ">
        <option value="1">SKILLS</option>
        <option value="Audiolog">Audiologist</option>
        <option value="Allerg">Allergist</option>
        <option value="Androlog">Andrologist</option>
   </select>
</div>
like image 35
IWI Avatar answered Nov 14 '22 21:11

IWI