除非调整浏览器窗口大小,否则Angular ui网格不显示内容 [英] Angular ui grid does not show content unless browser window is resized
问题描述
我正在使用angularjs 1.5.0 with angular ui grid 3.1.1。
当我在控制器主体中分配gridOptions(传递给grid指令)对象时,如下所示:
I am using angularjs 1.5.0 with angular ui grid 3.1.1. When I assign gridOptions (passed to the grid directive) object in controller body like this:
$scope.gridOptions = {
data: [{"mock2": 1, "mock1": 2}, {"mock2": 10, "mock1": 22} ]
};
HTML:
<div ui-grid="gridOptions"></div>
它按预期显示表格。但是当我尝试更改$ scope.on中的数据时:
It displays the table as expected. But when I try to change data inside $scope.on:
$scope.$on('update', function (event, passedFromBroadcast) {
$scope.gridOptions.data= [{"mock2": "set", "mock1": "inside"}, {"mock2": "$scope", "mock1": "on"} ] ;
});
它只渲染表格的框架,当包括分页时,它也会渲染与分页相关的控件 - 但不会内容本身。
内容(行和列标题)仅在我调整浏览器窗口大小后显示。
It renders only frame of the table, when including pagination it will also render pagination related controls - but not the content itself. Content (the rows and column headers) appear only after I resize my browser window.
- 为什么不当$ scope.on内的数据发生变化时,angular-ui网格更新表内容?
-
如何手动更新角度ui网格表?
我已经尝试过的事情:
- Why doesn't angular-ui grid update table content when the data changes inside $scope.on?
How can I manually update the angular ui grid table? Things I already tried:
$scope.gridApi.core.handleWindowResize(); // Does not work
$scope.gridApi.core.refresh(); // Does not work
$timeout(function(){$scope.gridOptions.data= [{"mock2": "set", "mock1": "inside"}, {"mock2": "$scope", "mock1": "on"} ] ;}) // Does not work
推荐答案
此代码存在两个问题,但仅在浏览器窗口调整大小后才显示表内容的原因是缺少定义宽度的css类和高度,基本(工作)示例:
There are a two issues with this code, but the reason for the table contents showing only after browser window resize is lack of css class defining width and height, basic (working) example:
.grid {
width: 500px;
height: 250px;
}
以HTML格式显示:
<div class="grid" ui-grid="gridOptions"></div>
其他问题(本线程中其他人提到:
The Other issue (mentioned by other people in this thread:
- 分配gridOption字段(数据但 columnDefs )必须在$ timeout内完成,另外在此之前需要清除data和columnDefs。否则它更改可能不会变得可见,并且表内容和标题将保持不变(ui-grid中的已知错误,如@maurycy所述)
- assigning gridOption fields (data but also columnDefs) must be done inside $timeout, additionally both data and columnDefs need to be cleared before that. Otherwise it change might not become visible and table contents and headers will remain unchanged (known bug in ui-grid as @maurycy mentioned)
这篇关于除非调整浏览器窗口大小,否则Angular ui网格不显示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!