Javascript 如何在行单击时展开-折叠ui网格分组?
我试图在行单击时展开和折叠分组,因为它应该与ui网格中的+和-图标一起工作 我试图从行模板调用treeButtonClick(行$event),如下所示。但它的功能是不触发Javascript 如何在行单击时展开-折叠ui网格分组?,javascript,angularjs,user-interface,angular-ui-grid,ui-grid,Javascript,Angularjs,User Interface,Angular Ui Grid,Ui Grid,我试图在行单击时展开和折叠分组,因为它应该与ui网格中的+和-图标一起工作 我试图从行模板调用treeButtonClick(行$event),如下所示。但它的功能是不触发 rowTemplate: '<div ng-click="treeButtonClick(row, $event)" ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cel
rowTemplate: '<div ng-click="treeButtonClick(row, $event)" ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell" ng-class="col.colIndex()" ui-grid-cell></div>',
rowTemplate:“”,
此外,在ui网格的分组中,这应该与+和-图标等效
请建议我如何使其工作,提前感谢您可以使用下面的函数展开所有行,$scope.gridApi.treeBase.expandAllRows(),使用collapseAllRows进行折叠的方法相同。 您可以为该列添加单元格模板,其中需要“+”和“-”,对于“+”单击,您可以通过这些函数展开这些行。解决方案是:
1.为表创建自定义模板:
<div ng-mousedown="grid.appScope.onMouseDown(row, $event)"
ng-click="grid.appScope.onDblClickRow(row.entity)" grid="grid" class="ui-grid-row">
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name"
class="ui-grid-cell" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader, custom: true }"
ui-grid-cell></div>
</div>
和打开行的函数:
var myAppScopeProvider = {
onClickRow: function (row, event) {
var rowIndex = row.grid.renderContainers.body.visibleRowCache.indexOf(row);
if (!angular.isUndefined(row.treeLevel)) {
vm.gridApi.treeBase.toggleRowTreeState(vm.gridApi.grid.renderContainers.body.visibleRowCache[rowNumber]);
}
}
};
你明白了吗?如果可以,请提供一个工作示例。NP,我找到了解决方案:)你能分享吗?工作起来很有魅力-但打字很小。。。设置
行索引
,然后参考行编号
var myAppScopeProvider = {
onClickRow: function (row, event) {
var rowIndex = row.grid.renderContainers.body.visibleRowCache.indexOf(row);
if (!angular.isUndefined(row.treeLevel)) {
vm.gridApi.treeBase.toggleRowTreeState(vm.gridApi.grid.renderContainers.body.visibleRowCache[rowNumber]);
}
}
};