Solved

cfgrid format="html" numbers sorted as text?

Posted on 2011-02-14
4
503 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 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