3.2.0

Sorting

How can I get the third column to sort nicely in this example?

var myData = [
["MSFT","<a href=''>Microsoft Corporation</a>", "a", "32,187.000", "55000"],
["ORCL", "<a href=''>Oracle Corporation</a>", "Z", "9,519.000", "40650"],
["SAP", "<a href=''>SAP AG (ADR)</a>", "d", "8,296.420", "28961"],
["CA", "<a href=''>Computer Associates Inter</a>", "0", "3,164.000", "16000"],
["ERTS", "<a href=''>Electronic Arts Inc</a>", "b", "2,503.727", "4000"],
["SFTBF", "<a href=''>Softbank Corp. (ADR)</a>", "z", ".000", "6865"],
["VRTS", "<a href=''>Veritas Software Corp.</a>", "4", "1,578.658", "5647"],
["SYMC", "<a href=''>Symantec Corporation</a>", "A", "1,482.029", "4300"],
["INFY", "<a href=''>Infosys Technologies Ltd.</a>", "H", "830.748", "15400"],
["INTU", "<a href=''>Intuit Inc.</a>", "977", "h", "6700"],
["ADBE", "<a href=''>Adobe Systems Incorporate</a>", "1", "1,230.817", "3341"],
["PSFT", "<a href=''>PeopleSoft, Inc.</a>", "8", "1,941.167", "8180"],
["SEBL", "<a href=''>Siebel Systems, Inc.</a>", "aho", "1,417.952", "5909"],
["BEAS", "<a href=''>BEA Systems, Inc.</a>", "7", "965.694", "3063"],
["SNPS", "<a href=''>Synopsys, Inc.</a>", "54532", "1,169.786", "4254"],
["CHKP", "<a href=''>Check Point Software Tech</a>", "zZAz", "424.769", "1203"],
["MERQ", "<a href=''>Mercury Interactive Corp.</a>", "324", "444.063", "1822"],
["DOX", "<a href=''>Amdocs Limited</a>", "01023", "1,427.088", "9400"],
["CTXS", "<a href=''>Citrix Systems, Inc.</a>", "6", "554.222", "1670"],
["KNM", "<a href=''>Konami Corporation (ADR)</a>", "784", ".000", "4313"]
];
Joel Maxson
August 2,
Is that the third column or column [3] (the 4th column)?
Greg
August 3,
third column (column[2])
Joel
August 3,
I was hoping to achieve the following order.

"0"
"01023"
"1"
"324"
"4"
"54532"
"6"
"7"
"784"
"8"
"977"
"A"
"aho"
"b"
"d"
"H"
"z"
"Z"
"zZAz"

Thanks for your help.
Joel
August 3,
Joel,

you can control the sort order using data/value property as opposed to data/text, which provides visible text. The default implementation for data/value is 'take data/text and try to convert it to numeric value or leave it as it is if conversion fails'. Apparently it doen't work well if you have mixed content in one column.

Here is the code which forces numeric sorting for columns 3-4 and string sorting for the rest:

obj.setDataProperty("value", function(i, j){
        if (j == 3 || j == 4 ){
            return Number(myData[i][j].replace(/[^0-9.]/g, ""));
        }
        else {
            return myData[i][j];
        }
    });

Alex (ActiveWidgets)
August 7,
You can also use data formatting classes to produce readable text and sortable values from the raw data:

http://www.activewidgets.com/messages/976-1.htm
http://www.activewidgets.com/documentation/reference/active.formats.date/index.htm
Alex (ActiveWidgets)
August 7,

This topic is archived.

See also:


Back to support forum