Description
I found this 2 unsolved but closed issues #21, #157.
I find your ng-grid super component - all my respect,
but I'd like to reopen the topic of variable row heights, because I think it is a KO feature, which unnecessarily forces many developers to search for another component.
It's a pity, that this nice component is missing the basic feature, which has also e.g. basic html table.
Why there is a cellTemplate feature, when I can't see cellTemplate content of multiple rows ?
Restriction to use cellTemplate only for 1 row narrows the possibilities quite a lot.
I made some hacks to bring it to work and have some suggestions at the end of this text to bring it to ng-grid.
-
custom css to turn on word-wrapping (it's not quit this topic, but it's correlated - whe you have long row, it breaks to multiple)
.ui-grid-cell-contents {
white-space: normal;
} -
custom css to turn on automatic row height
.ui-grid-cell {
height: auto !important;
} -
and 2. worked well - rows were wrapped and row heights automatically adapted.
I didn't found any other problem except of that the vertical slider wasn't shown ok (too low), because it still counted the rowHeight=30.
So in ui-grid.js (unstable) in var Grid = function Grid(options) { ...
I added this row
self.options.rowHeight = options.rowHeightCustom || self.options.rowHeight;�
Then it was possible to set the rowHeightCustom from Controller to the right value.
This hack brought to work correctly the vertical slider but only for equal row heights.
At the first look the vertical scrollbar height in ui-grid.js is counted in
function updateNativeVerticalScrollbar() { ... ... rowContainer.getCanvasHeight() ... }
and the getCanvasHeight() itself counts height as:
self.visibleRowCache.forEach(function(row){ ret += row.height; });
And there is the unlucky constantly fixed row.height set to 30.
For variable row heights:
On of the ways to get the row height for each row is e.g. in angular.module('ui.grid').directive('uiGridCell', ...
there is info $elm[0].offsetHeight / $elm[0].clientHeight
So for each row you can get the highest uiGridCell height value and set it as a variable row height (+ margins/padding eventually).
Taking it in account in getCanvasHeight()
self.visibleRowCache.forEach(function(row){ ret += row.variableHeight; });
the scrollbar might work fine.
If this would be settable in column definition with something like:
variableHeight : true;
It could still be kept the old functionality but also introduced the new one - at least for testing by community ;).
I didn't test all cases and situations and had only very short time to investigate it, but at the first glance it doesn't seem to be that much re-work to bring the variable row height to run.
I realize the ng-grid authors know best the background and all the struggle with the code to fix this.
I don't know if the above will navigate to the solution that fits the concept or not - but - maybe it helps as one of the ways ;).