dojo - dgrid custom sort with secondary sort column -
i'm using custom sort function on dgrid (pasted below). doesn't change sorting drastically, sorts 1 particular column uniquely , sorts others case-insensitive. i'd add secondary sort column named "scheduled" added sort when other column sorted. i'm not sure how go it. i've seen how override sort sort 2 columns, not when custom sort in play. secondary sort there, not matter other column clicked.
for reference i'm running dojo 1.10 , dgrid 1.0. data coming requestmemory dstore , i'd rather sort happen on grid rather @ store level. appreciated.
currgrid.on('dgrid-sort', function (event) { event.preventdefault(); var sort = event.sort[0]; currgrid.set('sort', function (a, b) { if (sort.property == "thisfield") { //special sort thisfield if (a[sort.property] !== 'undefined' && typeof a[sort.property] == "string") { var colora = a[sort.property].split("|"); var avalue = colora[0].tolowercase(); } if (b[sort.property] !== 'undefined' && typeof b[sort.property] == "string") { var colorb = b[sort.property].split("|"); var bvalue = colorb[0].tolowercase(); } if (string(avalue) == string(bvalue)) { var result = 0; } else if (dojo.string.trim(avalue) == "") { var result = true ? 1 : -1; } else if (dojo.string.trim(bvalue) == "") { var result = true ? -1 : 1; } else { var result = avalue > bvalue ? 1 : -1; } return result * (sort.descending ? -1 : 1); } else { //sort other fields same (except tolowercase) if (a[sort.property] !== 'undefined' && typeof a[sort.property] == "string") { var avalue = a[sort.property].tolowercase(); } else { var avalue = ""; } if (b[sort.property] !== 'undefined' && typeof b[sort.property] == "string") { var bvalue = b[sort.property].tolowercase(); } else { var bvalue = ""; } var result = avalue > bvalue ? 1 : -1; return result * (sort.descending ? -1 : 1); } }); currgrid.updatesortarrow(event.sort, true); }); currgrid.startup();
you below.
currgrid.on('dgrid-sort', function (event) { event.preventdefault(); var sortset = []; sortset.push(event.sort[0]); sortset.push({property: "scheduled"}); currgrid.set('sort', function (a, b) { var avalue, bvalue, result = 0; for(var = 0; < sortset.length; i++){ var sort = sortset[i]; if (sort.property == "thisfield") { //special sort thisfield if (a[sort.property] !== 'undefined' && typeof a[sort.property] == "string") { var colora = a[sort.property].split("|"); avalue = colora[0].tolowercase(); } if (b[sort.property] !== 'undefined' && typeof b[sort.property] == "string") { var colorb = b[sort.property].split("|"); bvalue = colorb[0].tolowercase(); } if (string(avalue) == string(bvalue)) { result = 0; } else if (dojo.string.trim(avalue) == "") { result = true ? 1 : -1; } else if (dojo.string.trim(bvalue) == "") { result = true ? -1 : 1; } else { result = avalue > bvalue ? 1 : -1; } return result * (sort.descending ? -1 : 1); } else { //sort other fields same (except tolowercase) if (a[sort.property] !== 'undefined' && typeof a[sort.property] == "string") { avalue = a[sort.property].tolowercase(); } else { avalue = ""; } if (b[sort.property] !== 'undefined' && typeof b[sort.property] == "string") { bvalue = b[sort.property].tolowercase(); } else { bvalue = ""; } //you need check here if(avalue != bvalue){ result = avalue > bvalue ? 1 : -1; return result * (sort.descending ? -1 : 1); } } } return 0; }); currgrid.updatesortarrow(event.sort, true); }); currgrid.startup();
i have concerns code, variables result, avalue , bvalue
local within if statement , yet being used outside statement. result in wrong results if other variables defined same name in global space. have modified them.
so second section needed check if avalue == bvalue
return 0.
Comments
Post a Comment