3.2.0

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
April 29,
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)
April 29,
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
April 30,
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
April 30,
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)
May 4,
Ok, i have done it...

Thanks...
Darius
May 5,
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
May 19,
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
May 28,
Darius,

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

http://www.activewidgets.com/messages/1252-0.htm
Alex (ActiveWidgets)
May 28,
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)
July 13,
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
August 10,
What if you have a blank date?

I get #ERR.

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


fixed it
Matt
February 14,
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
February 14,
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
April 26,
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
May 24,

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

How to sort this?

Shyam
August 17,

This topic is archived.

See also:


Back to support forum