Quick rendering of modified ASP.NET GridView w/ some jQuery magic

I came across a powerful performance saver using jquery while adding a column to an Asp.Net GridView client-side.  Put very simply, when creating the columns (including the header), set the display to "none".  Group the new header column and each new row's column with a special css class (like "somethingfunkythiswaycomes").

When all the rows have been changed (at the end of your .each jquery loop), simple call:

$(".somethingfunkythiswaycomes").show();

In firefox and chrome, the rendering is very fast and the whole action is at least as fast as a partial postback, w/o any annoying flicker.

NOTEIn IE (which continues to stand tall as the world's worst browser - maybe IE 9 will change my mind...), this technique does NOT work.  When I tried to use this on a 1000 row result set, it took 20 minutes to re-render.  20 freakin' minutes!?  Are you insane??  In Firefox 3 and Chrome 4, it took maybe 2 - 3 seconds!

Could be another case of Microsoft vs. Microsoft since they've officially adopted jQuery as one of their few open-source babies and I found this gargantuan performance difference using jQuery...

Needless to say, since most of the world is still stuck with the gunk that is IE, I had to do it all server-side, which turned out to be much, much more complex and annoying.  I needed to dynamically add/remove a column somehow so as not to bloat our html output from the server when we didn't need to (and yes, hidden columns still result in additional html).  I managed to do this using partial postbacks and hacking the view state.  Much more messy than a few simple lines of client-side javascript...

Comments

Popular posts from this blog

35x Improved T-SQL LevenShtein Distance Algorithm...at a cost

The hidden workings of __doPostBack - Full or Partial Postback?

Facing Death...dum de dum dum