:: Forum >>

Sorting Dates?

How can sort a column (filled with dates) ? I have to specifing a column type? (Now only sort alphabeticaly).
Thanks.

PD.- That's a great JS...
Darius
Thursday, April 29, 2004
If you are using XML data model - look at the example files:

/examples/grid/xml-dataset.htm
/examples/grid/xml-rss-msdn.htm

If you are using JS array - you can still use the same formatting objects, but plug them into you data retrieval function:

http://www.activewidgets.com/messages/976-1.htm
Alex (ActiveWidgets)
Thursday, April 29, 2004
The number of rows with dates are independent or this code is only for two columns? I have tried this but i think that only sort by year/day, not for year/month/day. Can you help me?
//example of date dd/mm/yyyy - 25/05/2004
var obj = new Active.Controls.Grid;
var date = new Active.Formats.Date;
obj.setRowCount(myData.length);
obj.setColumnCount(myColumns.length);
date.setDataFormat("auto");
date.setTextFormat("dd mm yyyy");
var formats=[date,date];
obj.setColumnText(function(i){return myColumns[i]});
obj.setDataText(function(i, j){return myData[i][j]});
obj.setDataValue(function(i, j){return formats[j].dataToValue(myData[i][j])});
Darius
Friday, April 30, 2004
Ok, forget previous message. I have five columns in javascript array(string,date,string,string,string). Date input example "31/12/2004". For sorting date i do this:
var string = new Active.Formats.String;
var date = new Active.Formats.Date;
var obj = new Active.Controls.Grid;

date.setDataFormat("auto");
date.setTextFormat("dd/mm/yyyy");
obj.setRowCount(myData.length);
obj.setColumnCount(myColumns.length);
var formats = [string,date,string,string,string];
            
obj.setDataText(function(i, j){return formats[j].dataToText(myData[i][j])});
obj.setDataValue(function(i, j){return formats[j].dataToValue(myData[i][j])});

The problem is that it changes the date... I don't know how but it happens... Result of this date "31/12/2004" appears like "12/05/2006".
Why happens that?

Thanks...
Darius
Friday, April 30, 2004
The Active.Formats.Date object can parse dates in RFC822 or ISO8061 formats and also the ones which are supported by JavaScript Date.parse function. JavaScript can parse dates in mm/dd/yyyy format but not dd/mm/yyyy as in your case. So you have to format the date on the server using one of the supported formats and then re-format it on the client (sounds very stupid).

All that becomes unnecessary if you find another way to provide proper numeric value into data/value function (which is used for sorting as opposed to data/text, which is formatted text to display). Maybe supply two arrays from the server - one for formatted text and one for sortable value?

Or rearrange day and month using RegExp?
Alex (ActiveWidgets)
Tuesday, May 4, 2004
Ok, i have done it...

Thanks...
Darius
Wednesday, May 5, 2004
I've done all this and my dates are coming out off 1 month
ie: 01/24/2004 is displayed as 00/24/2004.
Keith
Wednesday, May 19, 2004
I had the same problem... but i changed in the js file the line
"mm":"this.digits[this.date.getUTCMonth()]"
by
"mm":"this.digits[this.date.getUTCMonth()+1]"

And it seems to work...
Darius
Friday, May 28, 2004
Darius,

thanks a lot for the fix, I just posted the corrected code here:

http://www.activewidgets.com/messages/1252-0.htm
Alex (ActiveWidgets)
Friday, May 28, 2004
After changing the date class (i'm using the one from the link above), I still have the wrong date problem.... some dates show a wrong date, i.e. "2004-04-19" shows "4 jul 2005"...

I "solve" the problem using string for dates (i'm not to interest in sorting dates, yet).
Rodrigo (BRASIL)
Tuesday, July 13, 2004
The following should solve the problem for sorting dates in the format "dd/mm/yyyy" using RegExp as suggested by Alex above.

var xmlExprDDMMYYYY = /^(..).(..).(....)/;
var xmlOutDDMMYYYY = "$2/$1/$3";

var DDMMYYYY=function(data){
    return Date.parse(data.replace(xmlExprDDMMYYYY, xmlOutDDMMYYYY));
    };

obj.setDataFormat = function(format){
    if (format == "RFC822") {
        this.dataToValue = RFC822;
    }
    else if (format == "ISO8061") {
        this.dataToValue = ISO8061;
    }
    else if (format == "DDMMYYYY") {
        this.dataToValue = DDMMYYYY;
    }
    else {
        this.dataToValue = auto;
    }
};
Eoghan
Tuesday, August 10, 2004
What if you have a blank date?

I get #ERR.

Can that get ride of?
Darius
Friday, February 11, 2005
I would like to know that as well. Blank dates come up as #ERR
Matt
Monday, February 14, 2005
var _valueToDate = date.valueToText;
date.valueToText = function(v){
return v ? _valueToDate.call(this, v) : "";
}


fixed it
Matt
Monday, February 14, 2005
Nevermind, it doesn't work. When you do that, it won't sort propertly anymore. GUess i'm back to square one..

Anyone figure this out?
Matt
Monday, February 14, 2005
I still can't get dates to sort on dd/mm/yyyy formated dates. Does anyone have step by step instructions to make dd/mm/yyyy dates sort? I've been trying to piece fragments of code together from this forum without much success.

I would really appreciate a solution for this, it's driving me crazy!
Colin
Tuesday, April 26, 2005
has anyone got these formatted dates working properly?

I Have :

dateformat.setTextFormat("dd/mm/yyyy");

and an input of:

<DateCreated>11/09/2003</DateCreated>

giving me an output of 09/12/2003

Matt

Matt B
Tuesday, May 24, 2005

What if I have date in dd-mmm-yyyy (01-Jan-2005) format?

How to sort this?

Shyam
Wednesday, August 17, 2005

This topic is archived.


Back to support forum

Forum search