Follow up to CFGRID post, interesting queryConvertForGrid Behavior

This post is more than 2 years old.

A few days ago I blogged about CFGRID and noticing when the data inside was empty. I mentioned how you could get the data, but couldn't use the length value as the length would always equal the page size of the grid. Instead, you had to loop over the data and count the rows that were not null. I initially placed the blame on the grid, however, Scott Stroz pointed out that the issue was with queryConvertForGrid. Consider this example:

<cfset q = queryNew("id,name")> <cfset queryAddRow(q)> <cfset querySetCell(q, "id", 1)> <cfset querySetCell(q, "name", "Name 1")> <cfset queryAddRow(q)> <cfset querySetCell(q, "id", 2)> <cfset querySetCell(q, "name", "Name 2")>

<cfset r = queryConvertForGrid(q, 1, 10)> <cfdump var="#r#">

I've got a simple, hand made query with 2 rows. I converted it using queryConvertForGrid. Check out the result:

As you can see, the query was expanded to fill the page size. Why? I wrote up a quick test where I copied the query value and trimmed it down to just the two rows. I then returned that to my CFGIRD. Surprisingly the grid actually shrunk in size. When my data had 2 rows, only two rows showed up.

My guess, and let me stress, it's just a guess, is that the Adobe engineers assumed that folks wouldn't want their grids to shrink when they had less than 10 (or whatever page size) rows of data. That's a good assumption. It looks a bit wonky to see the grid shrink like that. However, I'm willing to bet that the Ext Grid could be programmed to not shrink like that. It kinda seems like the 'padding' we see here was simply a hack. Or maybe I'm wrong. I know the Ext grid that ships with CF is a bit old compared to the newest Ext grid, so maybe at the time it wasn't supported.

Anyway, this is probably a completely useless blog post, but I thought it was kind of interesting. As a general aside, I've been using jqGrid at Alagad and it's working real well. It's a nice grid plugin for jQuery.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Kumar posted on 4/16/2009 at 6:34 PM

I have also found jqGrid to be a lot better for grid purposes. CFGRID could still have its own place for very simple functionality, but jqGrid offers a lot more flexibility and control.

Comment 2 by Rigoberto Corrales posted on 9/12/2009 at 9:00 PM

Hi Ray:

The only examples I´ve seen about CF and Grids are with Ext or cfgrid, that is the same thing, like you said. But don´t you have any good example with jqGrid that could share us? Better if integrate a cfc and a query.

Thanks, in advance. Rigo

Comment 3 by Raymond Camden posted on 9/12/2009 at 9:02 PM

Nope, but when I searched for jqGrid I found a bunch - and by smarter people than I. :)

Comment 4 by Mickey posted on 8/26/2010 at 7:16 AM

Hey Ray...
Just wanted to say that this is certainly NOT a useless post. I just created a cfgrid and I personally prefer not to have the empty rows at the end... especially as I have a column with clickable url in it. CF likes to fill those fields with a clickable '-' dash which produces various results when you click them.

Reading your post inspired me to come up with a way to remove the empty rows within my cfc before returning the struct to the cfgrid. This not only helps in the case where you have fewer TOTAL results than your page size as in your example... it also helps when your last page of multiple pages doesn't match up to your page size.

Yes the grid suddenly shrinks... but I can live with that.
Thanks for the inspiration.

Comment 5 by Raymond Camden posted on 8/26/2010 at 7:37 AM

Woot! Glad it helped.