以角度ui网格绑定过滤器

时间:2016-03-09 14:45:03

标签: javascript angularjs angular-ui-grid 2-way-object-databinding

我试图根据条形图中的值过滤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,这是working plunker with custom table(我尝试用ui网格做的事情)

1 个答案:

答案 0 :(得分:0)

查看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 )
  });
相关问题