在angular-ui-网格中绑定过滤器

Bind filter in angular-ui-grid

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

在table指令中,有一个独立的作用域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>

请看一下 plunker with ui grid, and here is the working plunker with custom table(我想用 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 )
  });