Angular ui-grid set the filter field programmatically and update. Value not displayed

I have a ui grid with a bunch of columns using inline filtering. One of the columns is the owner. You can click the button that says “My items”. When you click this button, you must fill in the "Owner Filter" field with the user name and filter the elements. I set the filter as follows, as indicated in the documentation for the ui-grid:

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

However, "somename" never appears in the column filter header, and the data is never updated. I tried calling refresh () as well as notifyDataChange, but nothing works.

Thanks.

+4
source share
3 answers

Here is the right way to do it. By the way, there is no need to call the refresh () function.

  $scope.gridApi.grid.columns[3].filters[0] = {
    term: somename
  };
+7
source

I tried to answer this answer, but I had problems. I solved it with a little syntax change (changed grids.columns[2]to grid.getColumn('mycolumn'))

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

Hope this helps anyone looking

In my particular case, this is all 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>
+2
source

, , ( , ). . . :

$scope.MyGridName.grid.columns[2].filters[0] = { term: "CP" };
$scope.MyGridName.grid.refresh();

"CP" KendoUI. , . 2 [2] . , OP.

0
source

Source: https://habr.com/ru/post/1614533/


All Articles