ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

TreeNode $$treeLevel logic is wrong

Open ERobishaw opened this issue 9 years ago • 3 comments

If you want A ....A.1 ....A.2 ....A.3 B ....B.1 ....B.2 C D E

there is currently no way to inform the grid that C above does not have, and will never have children, and should not be a row-header.

Currently, the only way to ensure an item is not a row header is to set the $$treeLevel = undefined. *This allows the following to pass: *{'ui-grid-tree-header-row': row.treeLevel > -1}

However... The problem with this is row C above will always be bolded. B.2 has $$treeLevel = undefined, is a child of B, so it's OK C has $$treeLevel = null, which makes it correctly not a child of B, BUT, internally, it gets wrongly assigned to row.treeLevel =1, or something... actually not sure how it's passing the test.

See Plunker Demo In this example, "Morgan Sanford", row 45, should not be bold, it has no children. And, setting "Toggle Expand No Children" only partly helps, because the row is still bolded.

ERobishaw avatar Feb 19 '16 21:02 ERobishaw

Found a quick fix: set entity.$$treeLevel = -1 for all child-less entities. Then, fix the following code: *ui.grid.js, * finaliseAggregations: function( row ){ if ( row == null || typeof(row.treeNode.aggregations) === 'undefined' ){ return; } ...

Added the if (row == null) check.

ERobishaw avatar Feb 19 '16 21:02 ERobishaw

i just quickly observed, but you could use cellTemplate to customize row header of records which has no children.

tringuyenminh92 avatar Feb 28 '16 16:02 tringuyenminh92

This still doesn't work if there are one or more $$treeLevel === -1 rows at the start of the list. In createTree this causes the initial currentLevel of -1 to be decremented to -2 which leads to major problems.

A workaround is to make sure the top level rows at the start of the list have $$treeLevel === undefined and subsequent top-level rows have $$treeLevel === -1.

zamb3zi avatar Jul 20 '20 08:07 zamb3zi