:: Forum >> Version 2 >>

External sort model?

More information on this topic is available in the documentation section: /aw.ui.grid/sort-model.html.

I'd like to define a custom sort function for certain columns. Is that possible? Is that what the external sort model is for?
Kevin
Saturday, August 25, 2007
Sorting is controlled by AW.Formats classes. The following example shows sorting with the Number formatter vs the default string formatter. Also shows a custom formatter which sorts by string lengths.
<html>
<
head>
    <
title></title>
    <
style>body {font12px Tahoma}</style>
    <
script src="../../runtime/lib/aw.js"></script>
    <
link href="../../runtime/styles/xp/aw.css" rel="stylesheet"></link>
<
style>
    
#myGrid .aw-column-{width100px;}
    
#myGrid .aw-column-{width150px}
</
style>
</
head>
<
body>
    <
span id="myGrid"></span>
<
script>
var 
myData = [
    [
"1",        "1",    "zd"],
    [
"12",        "12",   "yyy"],
    [
"23",        "23",   "ggggg"],
    [
"100",        "100",  "555t"]
];
// custom sort to compare string lengths
StringLengthSort AW.Formats.String.subclass();
StringLengthSort.create = function() {
    var 
obj this.prototype;
    
obj.comparator = function(valuesgreaterlessequalerror){
        return function(
ij){
            var 
v1 values[i];
            if (
v1 == null) {
                
v1 "";
            }
            var 
v2 values[j];
            if (
v2 == null) {
                
v2 "";
            }
            if (
v1.length v2.length) {
                return 
greater * -1;
            }
            else if (
v1.length v2.length) {
                return 
greater 1;
            }
            return 
0;
        }
    };
}
var 
myHeaders = ["string""number""string length"];
var 
grid = new AW.UI.Grid;
grid.setId("myGrid");
grid.setHeaderText(myHeaders);
grid.setCellData(myData);
grid.setCellFormat(new AW.Formats.Number1);
grid.setCellFormat(new StringLengthSort2);
grid.setColumnCount(3);
grid.setRowCount(4);
grid.refresh();
</
script>
</
body>
</
html
Bryn
Sunday, August 26, 2007
Great, I'll give that a shot. Thanks.
Kevin
Sunday, August 26, 2007



This topic is archived.

Back to /aw.ui.grid/sort-model.html

Documentation:

Forum search