:: Forum >> Version 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
Friday, December 23, 2005
* bump *
Colin P.
Thursday, October 19, 2006
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
Thursday, October 19, 2006
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(indexdirection){
        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(indexdirection);
        }

        function 
compare(valueposdir){
            var 
greater = [], less = [];
            for (
0dir.lengthi++)
            {
                
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(
ij){
                for (
0dir.lengths++)
                {
                    var 
value[i][s], value[j][s], xy;
                    if (
typeof(a) != typeof(b)){
                        
types[typeof(a)];
                        
types[typeof(b)];
                        if (
y) {return greater[s]}
                        if (
y) {return less[s]}
                    }
                    else if (
typeof(a)=="number"){
                        if (
b) {return greater[s]}
                        if (
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 
ivalue = {}, pos = {};
        var 
rows this.getRowProperty("values");

        for (
i=0i<rows.lengthi++) {
            
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(valuepos, [directionpDirection]));

        
this.setRowProperty("values"rows);
        
this.setSortProperty("index"index);
        
this.setSortProperty("direction"direction);
    };
    ...
    
//  write grid html to the page
    
document.write(obj);
 
Alexey Shtokalo
Wednesday, November 8, 2006
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
Thursday, March 1, 2007
can i also know what are the variables and the inputs needed to be provided
kumaran
Thursday, March 1, 2007



This topic is archived.

Back to support forum

Forum search