Hi Michael!
I'd like help create a more surgical way of updating the widths of column headers and cells.
Right now the only way I've seen to do it is to change the data on the cols object and call .setColumns.
I think there's a good use case for a more specific method, and I think there's a chance it's a small and precise change.
I am hoping to get your thoughts, see how you'd like it implemented, then write it and do a pull request.
My understanding of the wiki made me think this is the right place to put this type of discussion.
I think others might be interested in a width update feature. There is some precedent out there:
My use case is sizing the columns to fit displayed content onViewportChanged. Because I'd like to to happen quickly and beautifully as one scrolls, performance is important. I have debounced the event but would like a little more responsiveness.
The sizing involves two steps:
- Measure all the visible content
- Apply calculated sizes
I have step 1 pretty fast now (0.5-2ms).
Step 2 is slow (~150ms) using the provided API (setColumns). I think this is just because that method kicks of a long chain of events including re-rendering the grid.
I investigated and it looks like there are 3 internal methods that handle width sizing:
`applyColumnHeaderWidths`
Resizes the column header cells individually
They fill the parent container as inline block elements
`updateCanvasWidth`
Resizes the parent container (size is based on summing the column widths)
Calls `applyColumnWidths` if the size is different, or always if passed `true`
`applyColumnWidths`
Writes the css rules for left and right offsets
If I exposed a method on the grid instance that was intended to update widths (given that the width data in the column object has already been set), it could look like this:
updateWidths = function() {
applyColumnHeaderWidths();
updateCanvasWidth(); // will call applyColumnWidths if there's been a change
return this;
}
$.extend(this, {
// ...
'updateWidths': updateWidths
// ...
});
Michael, do you like this? Think it is a good idea in general? How about the approach?