Closed sourabh-shankar closed 8 years ago
You can pad the totals in your function with leading zeroes, so they'll be correct when sorted as strings. "05000" will get sorted before "15000", but "5000" won't.
Note if you are using server-side publishing none of this will work, it can only sort by value, but it doesn't sound like you are.
Thanks! It worked. For anyone who is having same scenario, here is the solution;
fn:function(value, object, key) { var valArr = value.split('-'); var contat = valArr[0] + valArr[1]; var diff = 12 - contat.length; if(diff > 0) { var finalVal = Array(diff+1).join('0') + contat; } else { var finalVal = contat; } var html = "<span sortString=" + finalVal + ">" + value + "</span>"; return Spacebars.SafeString(html); }
Please note, 12 is the maximum length of string that can be shown i.e. 250000-500000
My column contains values like following: 0-15000 0-5000 20001-25000 12001-20000 30001-50000 20001-25000 ...
The default column sort is showing "0-15000" above "0-5000". I tried following method to custom return the value but sorting is still not working correctly:
function (value, object, key) { var valArr = value.split('-'); var total = Number(valArr[0]) + Number(valArr[1]); var html = "<span sortString=" + total + ">" + value + "</span>"; return Spacebars.SafeString(html); }
The correct sort should show values in following order: 0-5000 0-15000 12001-20000 20001-25000 20001-25000 30001-50000
How to do it?