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.
Archived Comments
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.
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
Nope, but when I searched for jqGrid I found a bunch - and by smarter people than I. :)
http://www.google.com/searc...
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.
Woot! Glad it helped.