:: Forum >>

date column sorting problem

I've been trying very hard to configure 1 of the columns in the grid as a date and get it sorted right, but no succes until now.

The date I want to see in the grid is in dd-mmm-yyyy format. If I keep it in mm-dd-yyyy the sorting works fine, but I can't get it to work in the dd-mmm-yyyy format.

I guess I have to change the CellValue of that column with SetCellValue (and I could even provide a hidden column in the right format), but I need help with the last part of the puzzle.

Hope anyone can help?!

Bart
Wednesday, January 25, 2006
Alex, Jim, any suggestions?

As always deadline coming soon...:-)
Bart
Wednesday, January 25, 2006
Sorry, but I don't work with date fields. Everything that I deal with are strings in my grids.
Jim Hunter
Wednesday, January 25, 2006
Alex or anyone else?
Bart
Thursday, January 26, 2006
Well first of let me show you some comparison without hyphens because it's easier to see.

Let's take todays date compare it
Jan 26 2006

mm-dd-yyyy
01262006

This will group dates by days

dd-mm-yyy
26012006

This will group dates by month

yyyy-mm-dd
20060126

This is the one you want to use as year, then month, then day is used to determine the sort.

Note if you check them as integer, or string for that matter the order will be as you seen as it is here. Let's take some other days in the last format

20050126
20051206
20060126

When sorted they will appear perfect. Now take a counter example in one of your other formats with the same dates

01262005
01262006
12062005

As you see they won't sort right. For sorting purposes, you MUST use this format yyyy-mm-dd, there is no way around it unless you are using a unix_timestamp.
Tony
Thursday, January 26, 2006
Ok Tony, thanks,I follow that so far...

I think it is possible to show a different "Text" and to have the yyyy-mm-dd just as value of the column, isn't it? (sorting is done on the value, isn't it?)

How do I set the Value of the column to i.e. myData [i][column8]? That would solve it completely!
Bart
Thursday, January 26, 2006
Bart,

this problem exists because textToValue() function for the date format does not work (yet) for dd-mmm-yyyy. One possible solution is to write this function yourself -

var date = new AW.Formats.Date;
date.textToValue = function(text){
return ... // ??
}

Another solution is to put your data into cellData (instead of cellText) in the format which works ok with existing date class and transform it to dd-mmm-yyyy (and value).

Example -

var myData = [
    ["text", "123", "12-1-2005"],
    ["more text", "56.1", "3-21-2004"]
]

var str = new AW.Formats.String;
var num = new AW.Formats.Number;
var date = new AW.Formats.Date;

num.setTextFormat("###.##");
date.setTextFormat("d-mmm-yyyy");

var obj = new AW.UI.Grid;

obj.setCellData(myData);
obj.setCellFormat([str, num, date])

obj.setColumnCount(3);
obj.setRowCount(2);

document.write(obj);
Alex (ActiveWidgets)
Thursday, January 26, 2006
Hi Alex,

I tried your solution with the setCellData(myData), but it somehow messes up my whole grid. In each cell of every column a whole "record-row" is written to. I.e. instead of dividing the row into 7 columns, all the data is written in one cell (and that for every cell)...?

I used obj.setCellText(function(col, row){return myData[row][col]}); before, and that worked/works perfect.

..and my date-column turned into an #ERR...

So, what's going wrong here, or any other suggestions?
Something like a date is akward to format differently in an app, just because the sorting won't work another way....There must be other people out there with working date-columns in their grids, other than in mm-dd-yyyy format?!

Anyone?!

Bart
Saturday, January 28, 2006
Bart,

it looks like the conflict with Prototype/Script.aculo.us libraries (which add method to global Object/Array prototypes). This problem will be fixed in RC and you can also try

obj.setCellData(function(col, row){return myData[row][col]});
Alex (ActiveWidgets)
Monday, January 30, 2006
Alex,

RC1 solved the problem. Great, thanks!

Bart
Bart
Thursday, February 2, 2006

This topic is archived.


Back to support forum

Forum search