我正在使用ui grid来显示数据列表,我正在尝试初始扩展所有行。
我正在尝试在onRegisterApi事件中执行此操作:
scope.GridOptions =
{
data: properties,
columnDefs:
[
{ name: "Full Address", field: "FullAddress" },
{ name: "Suburb", field: "Suburb" },
{ name: "Property Type", field: "PropertyType" },
{ name: "Price", field: "Price", cellFilter: 'currency'},
{ name: "Status", field: "Status" },
{ name: "Sale Type", field: "SaleType" },
{ name: "Date Created", field: "CreateDate", cellFilter: "date:'dd/MM/yyyy HH:mma'"}
],
expandableRowTemplate: 'template.html',
expandableRowHeight: 200,
onRegisterApi: (gridApi) =>
{
scope.gridApi = gridApi;
gridApi.expandable.on.rowExpandedStateChanged(scope,(row) =>
{
if (row.isExpanded) {
this.scope.GridOptions.expandableRowScope = row.entity;
}
});
gridApi.expandable.expandAllRows();
}
};
但上面的代码不起作用。看起来当我调用expandAllRows()时,行还没有渲染。
答案 0 :(得分:15)
就我而言,以下工作:
$scope.gridOptions = {
...
onRegisterApi: function(gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.grid.registerDataChangeCallback(function() {
$scope.gridApi.treeBase.expandAllRows();
});
}
};
答案 1 :(得分:1)
我发现我可以使用rowsRendered事件扩展所有行:
gridApi.core.on.rowsRendered(scope,() => {
if (!gridApi.grid.expandable.expandedAll && !initialized)
{
gridApi.expandable.expandAllRows();
initialized = true;
}
});
我使用了一个初始化的变量来识别这是否是第一次呈现行,因为我只想最初扩展所有行。
答案 2 :(得分:0)
对于我的所有网格用例,以上都没有。
$scope.gridApi.grid.registerDataChangeCallback(function() {
if($scope.gridApi.grid.treeBase.tree instanceof Array){
$scope.gridApi.treeBase.expandAllRows();
}
});
以下是我测试的每个案例的作品。在初始页面加载时,DataChangeCallback被调用两次(出于某种未知原因)。第一次,gridApi.grid.treeBase.tree是一个导致上面gridApi.grid.treeBase.tree.forEach问题的对象:
答案 3 :(得分:0)
这些答案都不适合我,以下是:
scope.gridApi.core.on.rowsRendered(null, () => {
scope.gridApi.treeBase.expandAllRows();
});