Why does ng-grid nested height not work?

I have a nested grid.

var faculty = angular.module('faculty', ['ngGrid']); faculty.controller('facultycontroller', function facultycontroller($scope, $http, $window) { $scope.facdata = [{ examname: 'test' },{ examname: 'test2' }]; $scope.gridOptions = { data: 'facdata', plugins: [new ngGridFlexibleHeightPlugin()], columnDefs: [ {field: 'examname',displayName: 'Exam Name'}, {field: '', displayName: 'Subjects' , cellTemplate: '<div ng-grid="gridOptions1" ></div>' }] }; $scope.fac1data = [{ abc: 'value', def: 'value2' }, { abc: 'value3', def: 'value4' }, { abc: 'value1', def: 'value4' }, { abc: 'value2', def: 'value4' }, { abc: 'value34', def: 'value4' }, { abc: 'value34', def: 'value4' }, { abc: 'value23', def: 'value14' }, { abc: 'value433', def: 'value5554' }, { abc: 'value3555', def: 'value4878' } ]; $scope.gridOptions1 = { plugins: [new ngGridFlexibleHeightPlugin()], data: 'fac1data', columnDefs: [ { field: 'abc',displayName: 'abc'}, { field: 'def',displayName: 'def'}] } }); 

See Plunker. I need to immediately see the entire nested data grid. I need to immediately see the data of the ng-grid children (no vertical scroll). But the height of the nested mesh does not work. My desire grid looks lower ...

Mater Detail Grid / Nested Grid

+8
javascript angularjs ng-grid
source share
2 answers

ng-grid was not intended for nested meshes: or even a dynamic cell height cell

If you look at the ng-grid ui-grid.html , you will see that the size is fixed in pixels:

  height: {{ grid.options.rowHeight }}px; 

see github

This CSS class is built into the template, leaving no room for rewriting to "auto". Because meshes are built using Div's rather than Tables , tabular relationships between rows and columns are difficult if each cell-div is free to decide its own behavior. Thus, nested lattices are a rather difficult task.


You CAN get the desired hack effect that resembles nested grids :

see plnkr

Rolled up mesh enter image description here

Note: A carriage has been added to indicate that parent lines are extensible. I did not add logic to hide operands for parent strings that have no children.

Extended grid enter image description here

see plnkr


Modify your JSon to include a column for Test, Name and andd Score. Use columns for test names or student names / scores. use parent identifier for children and specify id for parents:

 $scope.facdata = [{test: "Basic Physics Test", parentId:0,id:1,expanded:true}, {name: "NAME", Score: "SCORE",parentId:1,expanded:false}, {name: "John", Score: 77,parentId:1,expanded:false}, {name: "Jacob", Score: 66,parentId:1,expanded:false}, {name: "Jenny", Score: 94,parentId:1,expanded:false}, {test: "Advanced Physics Test",id:2, parentId:0,expanded:true}, {name: "NAME", Score: "SCORE",parentId:2,expanded:false}, {name: "Freddy", Score: 94,parentId:2,expanded:false}, {name: "Samantha", Score: 38,parentId:2,expanded:false}, {name: "Judy", Score: 100,parentId:2,expanded:false} ]; 

Set rowTemplate in the grid rowTemplate to use the ng-show directive for children in the expanded field

 $scope.gridOptions = { data: 'facdata', columnDefs: [{field: 'id',displayName:'',width:20, cellTemplate:'<div ng-show="row.getProperty(\'id\')" ng-click="toggleExpansion(row.getProperty(col.field))"><i class="fa fa-caret-right"></i></div>'}, {field: 'test', displayName: ''}, {field: 'name', displayName:''}, {field:'Score', displayName:'', cellTemplate: '<div class="ngCellText">{{row.getProperty(col.field)}}</div>'}], rowTemplate:'<div style="width: 600px" ng-show="row.getProperty(\'expanded\')"><div ng-repeat="col in renderedColumns" class="ngCell ">' + '<div ng-cell></div> </div></div>' 

Add a ToggleSubReport function to control the display of embedded data

 $scope.ToggleSubReport = function(id) { for (var i=0;i<$scope.facdata.length;++i){ if ($scope.facdata [i].parentId ===id){ $scope.facdata [i].expanded = !$scope.facdata [i].expanded; } } } 

see plnkr

:

:


Tracking Amin Uddin (Original Poster)

1) Nested grids are not possible: That was your main question and goal. This is what you have put generosity on. But as you can see from github the source for the grid line height (defined in pixels) and the responses from ng-grid , this is not an option that they even represent. The height of the NG-Grid cell is not really dynamic, since the ng-grid is intended for matching rows of the size of divs , not table (which can more naturally change the size of the row and row-row).

2) Sub-Grid of the type that I showed you can really combine complex relationships between children:. You can concatenate arrays before serializing them (or split JSON strings). to arrays, then combine them). You must override the fields that I used for master-detail from the unimaginative id/parentid , which I used for PK/FK from 2 lists.

+4
source share

This is just a hack example for each line with the same substring.

 <body ng-controller="facultycontroller"> <h1>Hello Plunker!</h1> <div ng-grid="gridOptions" ></div> </body> 
 var faculty = angular.module('faculty', ['ngGrid']); faculty.controller('facultycontroller', function facultycontroller($scope, $http, $window) { $scope.facdata = [{ examname: 'test' },{ examname: 'test2' }]; $scope.rowHeight = 30; $scope.updateGrid = function() { $scope.gridOptions = { data: 'facdata', rowHeight: $scope.fac1data.length * $scope.rowHeight, columnDefs: [ {field: 'examname',displayName: 'Exam Name'}, {field: '', displayName: 'Subjects' , cellTemplate: '<div ng-grid="gridOptions1" ></div>' }] }; } $scope.fac1data = [{ abc: 'value', def: 'value2' }, { abc: 'value3', def: 'value4' }, { abc: 'value1', def: 'value4' }, { abc: 'value2', def: 'value4' }, { abc: 'value34', def: 'value4' }, { abc: 'value34', def: 'value4' }, { abc: 'value23', def: 'value14' }, { abc: 'value433', def: 'value5554' }, { abc: 'value3555', def: 'value4878' } ]; $scope.gridOptions1 = { headerRowHeight: 0, data: 'fac1data', rowHeight: $scope.rowHeight, columnDefs: [ { field: 'abc', displayName: 'abc' }, { field: 'def', displayName: 'def' }] } $scope.updateGrid(); $scope.fac1data = [{ abc: 'value2', def: 'value4' }, { abc: 'value34', def: 'value4' }, { abc: 'value34', def: 'value4' }, { abc: 'value23', def: 'value14' }, { abc: 'value433', def: 'value5554' }, { abc: 'value3555', def: 'value4878' } ]; $scope.updateGrid(); }); 

Plunker

Edit: If the main line has different substring counts, it does not work. I have an idea. There should be a ui-grid plug and redesign it to automatic height. The official ui grid is a fixed project height in gridTemplate.html and uses an absolute top position.

0
source share

All Articles