Angular ui Grid(ng-grid)3:showHeader并没有改变任何东西 [英] Angular ui grid (ng-grid) 3: showHeader isn't changing anything
问题描述
我正在玩这个有角度的插件. 这是我的问题-我将不带标题的网格设置为默认值.当我想重新设置网格标题时,通过更改gridOptions.showHeader属性无法正常工作. 这是我的切换代码(一旦看到它,我就添加了refresh(),但是如果没有它,它就不会起作用):
I'm playing around with this angular plugin. Here's my issue - I'm setting the grid with no headers as default. When I want to set the grid header back, it doesn't work by changing the gridOptions.showHeader attribute. Here's my toggle code (I've added the refresh() once I saw it doesn't work without it but the refresh() doesn't help as well):
$scope.toggleHeader = function(){
$scope.gridOptions.showHeader = !$scope.gridOptions.showHeader;
$scope.gridApi.grid.refresh();
}
这里是plnkr: http://plnkr.co/edit/eEzSH5hKUTZFbkxiruSt
是否要打开和关闭网格标题?
Anyway to toggle the grid's header on and off?
为了显示这种更改的动机,我对代码进行了一些修改,以在某些gridStatus变量上使用观察程序(可以是任何值-在我的情况下,它是最小的):
In order to show the motivation of such a change, I've modified my code a bit to use watchers on some gridStatus variable (which could be anything - in my case it's minimize):
http://plnkr.co/edit/1fX6ZuqUt7xANO1P7MMG
推荐答案
许多gridOptions不是动态的-它们在初始化时设置,然后不重新评估.这是网格旨在减少观察者数量(从而最大程度提高性能)的目标的一部分,请参见: https://github.com/angular-ui/ng-grid/issues/1819
A number of the gridOptions aren't dynamic - they're set on initialisation and then not re-evaluated. This is part of the aim of the grid to minimise the number of watchers (and therefore maximise performance) Refer: https://github.com/angular-ui/ng-grid/issues/1819
简短的答案是,一旦网格渲染,就不能轻易更改它-您拥有一个带有标题的网格或一个没有标题的网格.但是,您可以重新渲染网格.最简单的方法是将ng-if放在您的grid指令上,然后将其切换,如下所示:
The short answer is that you can't easily change this once the grid renders - you either have a grid with headers or one without. You can, however, re-render the grid. The easiest way to do this is to put an ng-if on your grid directive, and then toggle it, which would look something like:
<div ui-grid="gridOptions" ng-if="refresh"></div>
和
function refreshGrid() {
$scope.refresh = false;
$timeout(function() {
$scope.refresh = true;
});
};
<div ui-grid="gridOptions" ng-if="refresh"></div>
and
function refreshGrid() {
$scope.refresh = false;
$timeout(function() {
$scope.refresh = true;
});
};
这篇关于Angular ui Grid(ng-grid)3:showHeader并没有改变任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!