Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting in a CFGRID

Status
Not open for further replies.

cturland

Programmer
Sep 25, 2000
66
GB
Regardless of what values you put in the CFGRID, it always treats them as strings and sorts accordingly.

Is there a better GRID control to use in Cold Fusion, or is there a way around this?
I have used leading zeros as a temporary solution but clearly this is not ideal.
 
We are trying to display some records from a database. Some of these values are numeric. We want the user to be able to sort these records so we have the sortascendingbutton and sortdescendingbutton visible. When the user sorts by the numeric columns, the values are treated as text, for example 1,5,15,122 would be sorted as 1,122,15,5 and the values are left justified.

As a temporary solution, we put leading zeros in, so our values would now be 001, 005, 015, 122 which solved the sorting problem, but looks a bit silly. In addition, clearly this will fail if there is a number greater than 999.

I have just put a few leading spaces in front of the numbers which looks better. As I know what my maximum value can be, all I need to do is put the correct number of leading spaces in.

For example, if the max value is 9999999 then my numbers will look like this: ______1, ______5, _____15, ____122 (where _ = space).

This is a better solution, but if anyone can suggest a grid which can deal with different datatypes that would be useful.

 
Can't you construct your own buttons and have them refresh the page and send URL variables (eg onclick=window.location.href=page.cfm?sortval=asc), and then dynamically construct the 'order by' clause of the cfquery used to populate the cfgrid, based on the URL query string values?
When you first hit the page just use CFPARAM to set the URL variable to asc or desc.
You could have a select list of field values and send this value in the query string so that you can sort by any grid column. You may be able to determine which column is selected and send this, however.

If you find an alternative to CFGRID I'd be interested to hear about it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top