mleibman/SlickGrid — pull request #897 by SimpleAsCouldBe (2014-03-06 23:09:14+00:00)
Title: Blazing Fast Column Width Update (with passing tests)

New method `grid.updateColumnWidths(columnDefinitions)` improves performance *dramatically* when all you need to do is adjust widths. I built it so that the whole grid isn't redrawn, only the styles are updated and the width on the header cells is modified.

Performance on my machine went from `76ms` to `2ms`, so there's a huge gain. Also, because the grid is not re-rendered in this model, all of the custom things folks (heh, me) might add to the column headers don't need to be re-drawn/bound.

I added a passing test for the traditional `setColumns` approach, and a passing test for the new `updateColumnWidths` approach. The test prints timing so you can see for yourself.

I use many of the grid features, but not all of them, so it's possible (likely?) I have missed something and this surgical resize option does not work if that feature is enabled. If so, I'd be happy to add a test case for it and fix it.

In terms of arguing for its broad applicability, I have collected the following evidence. I think this new method would help anyone trying to autofit columns to content (this is my use case, in fact.)

#### Prior requests/discussion/issues:

http://stackoverflow.com/questions/6794656/how-do-i-autosize-the-column-in-slickgrid
https://groups.google.com/forum/#!topic/slickgrid/dYtmwhfFCTw
https://groups.google.com/forum/#!topic/slickgrid/TmvDUzaKfPk
https://github.com/mleibman/SlickGrid/issues/305
http://stackoverflow.com/questions/15200574/slickgrid-column-width-should-automatically-get-resized-according-to-widest-row
https://github.com/mleibman/SlickGrid/issues/568
https://github.com/mleibman/SlickGrid/pull/733
http://stackoverflow.com/questions/12071844/is-it-possible-to-change-width-of-a-column-in-slickgrid-programatically

There's also a little google groups post I made attempting to get your thoughts on the idea:
https://groups.google.com/forum/#!topic/slickgrid/BBB-Qhg7TvU