Exploring ColdFusion 9: The Four New Data Types in CFGrid

ColdFusion 9

ColdFusion 9 brings four new data types to the html cfgrid.  As the docs state:

ColdFusion 9: Added boolean, date, numeric, and string_noCase to the
type attribute values supported in HTML grids

 

Lets take a look at these new types.  Here's a sample query from the art table that I added a date to and called it, well, aDate:

Query Dump

I'll display these using the following cfgridcolumn tags:

<cfgridcolumn name="artname" type="string_noCase">
<cfgridcolumn name="isSold" type="boolean">
<cfgridcolumn name="price" type="numeric">
<cfgridcolumn name="aDate" type="date">

Whats cool is that ColdFusion or ExtJS (I'm not sure which) is going to automatically try and convert these types from the data where possible.  The grid looks like this:

A quick run through of the various types;

  • string_noCase specifies that the column will be sorted without regards to case. 
  • The boolean type will show a checkbox, checked if the boolean is true.  From this example you can see that it is smart enough to convert 0 and 1's into Boolean as well as true and false. 
  • The price column is set to numeric which limits the editing of the column to just numbers. 
  • Leaving the best for last is the date type which when editing displays a nice calendar option.

Overall some pretty cool additions that make the cfgrid tag more useful.

Here's the full code to generate the above:

<cfquery name="getArt" datasource="cfartgallery">
select ARTID, ARTNAME, DESCRIPTION, ISSOLD, PRICE, CURRENT_DATE aDate 
from ART 
</cfquery>
<cfdump var="#getArt#" top="10">

<cfform>
<cfgrid format="html" name="art" query="getArt" align="left" selectmode="edit">
	<cfgridcolumn name="artname" type="string_noCase">
	<cfgridcolumn name="isSold" type="boolean">
	<cfgridcolumn name="price" type="numeric">
	<cfgridcolumn name="aDate" type="date">
</cfgrid>
</cfform>

CF Mitrah said:
 
How can we enable sorting for "boolean" data type column?
 
posted 263 days ago
Add Comment Reply to: this comment OR this thread
 
CF Mitrah said:
 
I found a hack for this.I just added onload="enableSort" in cfgrid. It will help to enable sorting.

function enableSort(grid){
grid.getColumnModel().getColumnAt(1).sortable = true;
}
 
posted 262 days ago
Add Comment Reply to: this comment OR this thread
 
samfarmer said:
 
@CF Mitrah: Cool. Thanks for posting the solution.

I wonder why sorting on boolean gets turned off by default?
 
posted 262 days ago
Add Comment Reply to: this comment OR this thread
 
freddy said:
 
The sort by string_nocase does not work. It still sorts uppercase first then lowercase.
 
posted 165 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Twitter
You should follow me on Twitter here
About Me
I am a 34-year old Web Developer specializing in ColdFusion. I live and work in downtown Washington, DC with my wife and two daughters. Read more About Me

2007 CFeMmy Best Newcommer winner
As voted on by fellow CF Bloggers.