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,
// 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);
This topic is archived.
ActiveWidgets is a javascript library for creating user interfaces. It offers excellent performance for complex screens while staying simple, compact and easy to learn. Deployed by thousands of commercial customers in more than 70 countries worldwide.
Copyright © ActiveWidgets 2021