, , . , JS , ng-:
var row_height = 30;
$scope.height = row_height;
$scope.height_px = row_height + 'px';
row_height. rowExpanded rowCollapsed :
$scope.gridOptions = {
rowHeight: row_height,
enableSorting: true,
enableFiltering: false,
onRegisterApi: function(gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.treeBase.on.rowExpanded(null, function(row) {
addHeight(row.treeNode.children.length);
});
$scope.gridApi.treeBase.on.rowCollapsed(null, function(row) {
var count = row.treeNode.children.length;
for(var i=0; i < row.treeNode.children.length; i++) {
count += getChildCount( row.treeNode.children[i]);
}
deductHeight(count);
});
}
}
, addHeight(), deductHeight() getChildCount() :
var addHeight = function (num_rows) {
$scope.height += num_rows * row_height;
$scope.height_px = $scope.height + 'px';
};
var deductHeight = function (num_rows) {
$scope.height -= num_rows * row_height;
if($scope.height <= 0) {
$scope.height = row_height;
}
$scope.height_px = $scope.height + 'px';
};
var getChildCount = function (node) {
var count = 0;
if(node.state == 'expanded') {
node.state = 'collapsed';
count += node.children.length;
for(var i=0; i < node.children.length; i++) {
count += getChildCount(node.children[i]);
}
return count;
} else {
return 0;
}
};
, node count, a node. - , .
, $scope.height_px, . , ng-style="{ 'height': height_px }" :
<div id="gridTree-1" ui-grid="gridOptions" class="grid" ui-grid-tree-view ui-grid-auto-resize ng-style="{ 'height': height_px }"></div>
, , , , . , -, , . ui-grid.js. 3.1.1 2721 event.preventDefault();. , .