Solved

cfgrid format="html" numbers sorted as text?

Posted on 2011-02-14
4
504 Views
Last Modified: 2012-05-11
I am using CF9 and cfgrid, with cfgrid format="html".  

The cfgrid sorts simple numbers in text order, not number order:

0
1
10
101
11
12
2
21

How do I fix this?
The grids sorts correctly if format="flash", but I want to use format="html".

Here is my code:
<!--- cfgrid.cfc --->
<cffunction name="getLogins" returnType="query" access="remote" hint="Retrieves logins">
<cfset var data="">
<cfquery name="data" datasource="dsn">
SELECT PreferredName, TotalLogins FROM cfgriddata
</cfquery>
<cfreturn data>
</cffunction>

Open in new window

and
<!--- test.cfm --->
<cfinvoke component="cfgrid" method="getLogins" returnvariable="logins">
</cfinvoke>
<cfform action="" method="post" id="form1">
 <cfgrid name="data" width="260" query="logins" colheaderbold="Yes" font="Tahoma" fontsize="14" rowHeaders="No" height="600" format="html"> 
	<cfgridcolumn name="PreferredName" header="Name" width="200"> 
	<cfgridcolumn name="TotalLogins" type="numeric" header="Logins" width="60" dataalign="right"> 
</cfgrid>
</cfform>

Open in new window

The mysql table is:
-- ----------------------------
--  Table structure for `cfgriddata`
-- ----------------------------
DROP TABLE IF EXISTS `cfgriddata`;
CREATE TABLE `cfgriddata` (
  `id` smallint(6) NOT NULL AUTO_INCREMENT,
  `PreferredName` varchar(24) NOT NULL DEFAULT '',
  `TotalLogins` smallint(6) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=851 DEFAULT CHARSET=utf8 PACK_KEYS=1;

-- ----------------------------
--  Records of `cfgriddata`
-- ----------------------------
BEGIN;
INSERT INTO `cfgriddata` VALUES ('19', 'Carol', '11'), ('33', 'Mary', '1'), ('98', 'Lucille', '0'), ('413', 'Max', '21'), ('679', 'Kate', '10'), ('708', 'Julie', '101'), ('728', 'William', '3'), ('748', 'Dawn', '12'), ('785', 'Judy', '2');
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;

Open in new window

0
Comment
Question by:ShanghaiD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 34894599
Hi,

did you try to put order by within query.


<cfquery name="data" datasource="dsn">
SELECT PreferredName, TotalLogins FROM cfgriddata order by totallogins
</cfquery>

Open in new window

0
 

Author Comment

by:ShanghaiD
ID: 34894629
Yes, it sorts correctly then (when the grid first loads the query result).  However, the sort order reverts to text order when the cfgrid sorts each column (PreferredName by person name -- correclty -- and TotalLogins by number -- incorrectly -- reverts to text sort order).
0
 

Accepted Solution

by:
ShanghaiD earned 0 total points
ID: 34897247
I've found a fix by changing from "query" to "bind" and now cfgrid sorts correctly with format="html" (which I want instead of format="flash" so I can use Raymond Camden's neat formatting tricks).

Exctracted revisions to my code are below (in case anyone is interested):
<cffunction name="logins"
access="remote"
returntype="struct">
....
....
<cfreturn QueryConvertForGrid(data,
ARGUMENTS.page,
ARGUMENTS.pageSize)>
</cffunction>


<cfgrid
....
....
bind="cfc:cfgrid.getLogins({cfgridpage},
{cfgridpagesize},
{cfgridsortcolumn},
{cfgridsortdirection})">

Open in new window

0
 

Author Closing Comment

by:ShanghaiD
ID: 34936396
Alternative solution found.
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question