3.2.0

date format

Hi,
i have a problem regarding the date sorting. What is happening is am gettingthe date in the format ddmmmyyyy taking this am date am formatting it in to string but wat i observed in the sorting is it formats the date in the alphebatical order? can any1 help me out?
shanky
February 13,
You should specify that the cell content should be interpreted as dates using setCellFormat() method. It allows to sort dates as 'values' instead of alphabetically.

http://www.activewidgets.com/aw.ui.grid/cell-format.html
Alex (ActiveWidgets)
February 13,
Hi alex,
I tried with what u said but it was asking to check the method am using the Version1. Please help its urgent !!!!!!
anand
March 8,
I use these functions for sorting

/* set data types for column sorting
*/

/* functions which return sortable data */

//strings
function string(text){return text;};          

//numbers
function number(text){return Number(text.replace(/[ ,%$]/gi, '').replace(/\((.*)\)/, '-$1'))}; 

//date/time (dd-mm-yyyy, hh:mm)
function datetime(text){var oData = new Date(); return Number(Date.UTC(text.substr(6, 4),text.substr(3, 2),text.substr(0, 2),text.substr(12, 2),text.substr(15, 2)))}

/* array with column sort types */
var toValue = [number,string,string,date]; //this is for a 4-column grid, column 1 contains numbers, column 4 a date etc

obj.setDataProperty('value', function(i,j){return toValue[j](obj_data[i][j]);});

/* display object on screen */
document.write(obj);


You could use them and rewrite the datetime function (the text.substr.... part)

Good luck
Rekcor
March 8,
The correct code for above post

/* set data types for column sorting
*/

/* functions which return sortable data */

//strings
function string(text){return text;};          

//numbers
function number(text){return Number(text.replace(/[ ,%$]/gi, '').replace(/\((.*)\)/, '-$1'))}; 

//date/time (dd-mm-yyyy, hh:mm)
function datetime(text){var oData = new Date(); return Number(Date.UTC(text.substr(6, 4),text.substr(3, 2),text.substr(0, 2),text.substr(12, 2),text.substr(15, 2)))}

/* array with column sort types */
var toValue = [number,string,string,datetime]; //this is for a 4-column grid, column 1 contains numbers, column 4 a date etc

obj.setDataProperty('value', function(i,j){return toValue[j](obj_data[i][j]);});

/* display object on screen */
document.write(obj);


Good luck
Rekcor
March 8,
Hi Rekcor,
To be more specific my problem is as followed---
I have a grid developed as followed with the first row highlighted.
Type Date Subject
CR 08Mar2007 Sample
FL 08Mar2007 Test
CN 07Mar2007 Test
CR 06Mar2007 Sample
CM 06Mar2007 Test
CN 08Jan2007 Test
CN 08Jan2007 Test
When i click on the date column i get the sorting as------
Type Date Subject
CN 07Mar2007 Test
CR 06Mar2007 Sample
CM 06Mar2007 Test
CN 08Jan2007 Test
CN 08Jan2007 Test
CR 08Mar2007 Sample
FL 08Mar2007 Test
Please help me out as this is not the correct sorting. I guess we need to have the dispaly as-------
Type Date Subject
CN 07Mar2007 Test
CR 06Mar2007 Sample
CM 06Mar2007 Test
CN 08Jan2007 Test
CN 08Jan2007 Test
FL 08Mar2007 Test
CR 08Mar2007 Sample
THANKS IN ADVANCE!!!!!!!
anand
March 8,
You should convert your dates to numbers, as those are sortable. So if you manage to put your dates in the YYYYMMDD format, the sorting works well. Note: the conversion only has to take place before sorting, so the things displayed on the screen can be 08Mar2007 etc.

So how could we convert 08Mar2007 to YYYYMMDD? The only *small* probleem is the month, because it is a string, we have to convert is to a number:

var asMonths = new Array();

asMonths['Jan'] = 1;
asMonths['Feb'] = 2;
asMonths['Mar'] = 3;

etc.


Now the sort function becomes something like (haven't tested it):

//convert ddMMMYYYY --> yyyymmdd
function datetime(text){var oData = new Date(); return Number(Date.UTC(text.substr(7, 4),asMonths[text.substr(3, 2)],text.substr(0, 2)))}


Hope this helps
Rekcor
April 11,
An effective workaround,
capture your date format in raw date (ie, long type).

set the cell
<%for(i=0; i<length; i++ ){%>
obj.setCellValue(<%=dateTime%>,0,<%=i%>);
<%}%>

var str = new AW.Formats.String;
var numct = new AW.Formats.Number;

numct.setTextFormat("########");
obj.setCellFormat([numct, str, str, ...]);
obj.setSortColumn(0);
obj.setSortDirection("descending", 0);

This will work in any extreme condition
Sanjay Sharma
April 12,

This topic is archived.

See also:


Back to support forum