Using data formats with JS array
When the data comes from XML or CSV file - quite often it is necessary to transform it from the 'transport' format to some nicer visual form, say from ISO8601 date to more readable 'dd-mmm-yy'. For this purpose you can use the set of formatting classes -
AW.Formats.String
AW.Formats.Number
AW.Formats.Date
Those classes provide dataToText() and textToData() methods which are used to transform data from a 'transport' format to readable cell text (or, more precisely, html).
Another pair of methods - dataToValue() and valueToData() - provide transformations to the value type (String, Number or Date as opposed to readable text) which you can process programmatically, i.e. add, compare, sort (currently used for sorting).
The same approach could be used with JS array, however when the JS array is produced by the server-side script you can already pre-format the data for display and avoid dataToText() client-side transformation.
In this case the formatting classes might still be necessary for the correct sorting, but as the data is already in text form - the sorting procedure will call textToValue() method (instead of dataToValue()).
However if you for some reason want to send the data in some intermediary form and process it on the client - you can do it with JS array too, just using setCellData() method instead of setCellText() together with formatting classes:
To summarize - the grid uses cell text for display, cell value for sorting and cell data if the data comes in some intermediary format and formatting classes provide methods which transform data to text, value or back.
AW.Formats.String
AW.Formats.Number
AW.Formats.Date
Those classes provide dataToText() and textToData() methods which are used to transform data from a 'transport' format to readable cell text (or, more precisely, html).
Another pair of methods - dataToValue() and valueToData() - provide transformations to the value type (String, Number or Date as opposed to readable text) which you can process programmatically, i.e. add, compare, sort (currently used for sorting).
The same approach could be used with JS array, however when the JS array is produced by the server-side script you can already pre-format the data for display and avoid dataToText() client-side transformation.
In this case the formatting classes might still be necessary for the correct sorting, but as the data is already in text form - the sorting procedure will call textToValue() method (instead of dataToValue()).
var myText = [
["aaa", "111", "2-21-2005"],
["bbb", "22", "11-1-2005"]
];
var string = new AW.Formats.String;
var number = new AW.Formats.Number;
var date = new AW.Formats.Date;
var obj = new AW.UI.Grid;
obj.setCellText(myText);
obj.setCellFormat([string, number, date]);
obj.setColumnCount(3);
obj.setRowCount(2);
document.write(obj);
However if you for some reason want to send the data in some intermediary form and process it on the client - you can do it with JS array too, just using setCellData() method instead of setCellText() together with formatting classes:
var myData = [
["aaa", "111", "2-21-2005"],
["bbb", "22", "11-1-2005"]
];
var string = new AW.Formats.String;
var number = new AW.Formats.Number;
var date = new AW.Formats.Date;
var obj = new AW.UI.Grid;
obj.setCellData(myData);
obj.setCellFormat([string, number, date]);
obj.setColumnCount(3);
obj.setRowCount(2);
document.write(obj);
To summarize - the grid uses cell text for display, cell value for sorting and cell data if the data comes in some intermediary format and formatting classes provide methods which transform data to text, value or back.
Alex (ActiveWidgets)
January 10,