ColdFusion grid formatting issues explained
Tags: Coldfusion
In a previous post I spoke how that in ColdFusion 9 that anything that was considered to be a date and had a time part to the string, ColdFusion 9 would actually strip the time and reformat the string to its custom rendering.
Since the release of ColdFusion 9.01 I again had a look into this problem, and although the time is no longer stripped from the string. Something else is very unexpected as a result to this new change.
This is something that one has to take into consideration when migrating over to ColdFusion 9 and you are using the cfgrid tag, to display data back to the user.
In the following images you can clearly see that the query is indeed returning the correct information on both counts, so we can eliminate any problems that may have been introduced into the cfquery tag.
Image from ColdFusion 8
Image from ColdFusion 9.01
When we then look at the data that is being displayed in the cfgrid itself we can see that there is a major difference in what its going on, in ColdFusion 8 it looks like the following image
And in ColdFusion 9.01 it looks like this.
Now before ColdFusion 9.01 was released as shown in my previous blog, the format of the string would always be a date and the time was always stripped from the string.
So why is this a problem for anyone to worry about, well if you want to get to the crunch of the problem there isn't really a major problem here and that is because Adobe have introduced a new attribute for HTML grids, to the column tag that allows you to format the data with a mask. But the hassle of going and changing code because the grid is no longer backward compatible is not something that I would really consider to be an acceptable practice either.
In other words I am saying that there was no care in what was changing here, and that shows in the 3 different versions that is being displayed. In ColdFusion 8 it was treated as a string and it was displayed as a string, and in ColdFusion 9.01 it now appears to be an actual JavaScript date object.
The upside to this is that in ColdFusion 9.01 is that we can now format this anyway we like using the mask grid column attribute, however I think that if you look at this from a different perspective Adobe may have not given this much thought either.
Why do I say that?
At the time of writing this mask attribute is not on the documentation that can be found on the Adobe docs website, so until that happens let me explain what Adobe have done. The attribute mask is now enabled for HTML grids as well, however if you read the notes on the changes it clearly indicates that the default behavior for formatting this is m/d/y.
However as you can see this was what was happening in ColdFusion 9.0, but in ColdFusion 9.01 it seems that this was reversed or something else is going wrong.
What would have been better?
First I can understand why this behavior has been introduced, however the default behavior of the grid output should have matched what is happening in ColdFusion 8. The reason behind this is because if you are like me and others, you may have already had added a custom renderer to render the date anyway and the data returned by ColdFusion 9/9.01 just breaks your application.
Now what I would have done is added a new attribute to the grid column tag, that was along the lines of cellRender. That allowed the user to provide a custom way to format any cell in the grid, as this is still a major let down for the current implementation of the cfgrid.
-
<p> Just to add one note - you say this is not documented anywhere. That is not true. It is documented in the new features guide for CF901. The online core reference is still for 900. In my opinion it should be updated.</p>
# Posted By Raymond Camden | 7/21/10 6:39 AM -
Ray,
That's correct the docs for ColdFusion 9, is what I was referring too. yes the changes are in the whats new and release notes for the updater. But must people will be going to the docs or what was known as livedocs first.
So the sooner that gets updated the better I think.
# Posted By Andrew Scott | 7/21/10 8:19 PM



TweetBacks