在角度 UI 网格中绑定过滤器

Bind filter in angular-ui-grid

本文关键字:绑定 过滤器 网格 UI      更新时间:2023-09-26

我正在尝试根据条形图中的值过滤 ui 网格,但我不知道如何在 ui 网格中绑定此值。

在表指令中,存在要传递country的隔离作用域:

app.directive("countryItem", function() {
  return {
    restrict: "E",
    templateUrl: "table.html",
    //isolated scope and 2-way bind country
    scope: {
      country: "="
    }
  };
});

下一个将在 ui 网格中绑定。我尝试在网格定义(filter:country)中直接绑定,但它不起作用:

<div id="grid1" ui-grid="gridOptions" ui-grid-selection ui-grid-pagination ui-grid-resize-columns class="grid" external-scopes="$scope" filter:country></div>

请看一下带有 ui 网格的 plunker,这是带有自定义表的工作 plunker(我正在尝试使用 ui 网格做什么)

看看 http://plnkr.co/edit/5LBpfCRgdaIIqQKJKhgs?p=preview。

您需要在国家/地区更改时动态设置filter.term

  $scope.$watch('country', function () {
    $scope.gridOptions.columnDefs[0].filter.term = $scope.country;
    $scope.gridApi.core.notifyDataChange( uiGridConstants.dataChange.COLUMN )
  });