3.0 beta 2

Sorting Dates?

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

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


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

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;
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])});
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;

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?

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...

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.
May 19,
I had the same problem... but i changed in the js file the line


And it seems to work...
May 28,

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

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;
August 10,
What if you have a blank date?

I get #ERR.

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

fixed it
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?
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!
April 26,
has anyone got these formatted dates working properly?

I Have :


and an input of:


giving me an output of 09/12/2003


Matt B
May 24,

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

How to sort this?

August 17,

This topic is archived.

See also:

Back to support forum


Version 2

Looking for AW 2.6 ?
The old site is here.