3.0 beta 2

how to make grid sort by multi columns ,not only by one column?

how to make grid sort by multi columns,not only by one columns?Now only one column can be set for sort the data.
wmgreat
December 23,
* bump *
Colin P.
October 19,
Did you mean like a groupby?, you must make a funtion and compare all the columns making a reorganizatiion of all the row indices. of all the columns.
Paul
October 19,
The sample how can you sort columns with regards to previous sort column and direction... It's easy to modify code for your needs:

//  create ActiveWidgets Grid javascript object
    var obj = new Active.Controls.Grid;
    ...
    // override sort function with new features
    obj.sort = function(index, direction){
        var pIndex     = this.getSortProperty('index');
        pIndex = (pIndex != index) ? pIndex : -1;
        var pDirection = this.getSortProperty('direction');
        pDirection = (pDirection != 'none') ? pDirection : 'ascending';

        var model = this.getModel("row");
        if (model.sort) {
            return model.sort(index, direction);
        }

        function compare(value, pos, dir){
            var greater = [], less = [];
            for (i = 0; i < dir.length; i++)
            {
                greater[i] = -(less[i] = ((dir[i] == "descending") ? 1 : -1));
            }
            var types = {
                "undefined" : 0,
                "boolean"   : 1,
                "number"    : 2,
                "string"    : 3,
                "object"    : 4,
                "function"  : 5
            };

            return function(i, j){
                for (s = 0; s < dir.length; s++)
                {
                    var a = value[i][s], b = value[j][s], x, y;
                    if (typeof(a) != typeof(b)){
                        x = types[typeof(a)];
                        y = types[typeof(b)];
                        if (x > y) {return greater[s]}
                        if (x < y) {return less[s]}
                    }
                    else if (typeof(a)=="number"){
                        if (a > b) {return greater[s]}
                        if (a < b) {return less[s]}
                    }
                    else {
                        var result = ("" + a).localeCompare(b);
                        if (result) {return greater[s] * result}
                    }
                }
                return 0;
            }
        }

        if (direction && direction != "ascending" ) {
            direction = "descending";
        }
        else {
            direction = "ascending";
        }

        var i, value = {}, pos = {};
        var rows = this.getRowProperty("values");

        for (i=0; i<rows.length; i++) {
            value[rows[i]] = [this.getDataProperty("value", rows[i], index),
                (pIndex != -1) ? this.getDataProperty("value", rows[i], pIndex) : 0];
            pos[rows[i]] = i;
        }

        rows.sort(compare(value, pos, [direction, pDirection]));

        this.setRowProperty("values", rows);
        this.setSortProperty("index", index);
        this.setSortProperty("direction", direction);
    };
    ...
    //  write grid html to the page
    document.write(obj);
Alexey Shtokalo
November 8,
Alex
this code is working out fine fine for me for the descending order but if its the ascending i face few problems can u help me out? I have a grid with the Columns named type, authority, subject, date, facilities.
I have few records having equal data in the rows when sorting is done for these records i want the sorting to be done based on the date for the other columns which have the equal row data.
kumaran
March 1,
can i also know what are the variables and the inputs needed to be provided
kumaran
March 1,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.