I had the need to use multisort + customsort in order to sort in a turbotable several fields included one that contains cells with object values like {value: xyz} (output of a dropdown selection).
Beacuse of the feature of custom sort doesn't work if multisort is turned on, I've directly modified the multisort method in turbotable code adding the following lines:
Code: Select all
Table.prototype.multisortField = function (data1, data2, multiSortMeta, index) {
var value1 = this.objectUtils.resolveFieldData(data1, multiSortMeta[index].field);
var value2 = this.objectUtils.resolveFieldData(data2, multiSortMeta[index].field);
var result = null;
if (typeof value1 == 'string' || value1 instanceof String) {
if (value1.localeCompare && (value1 != value2)) {
return (multiSortMeta[index].order * value1.localeCompare(value2));
}
//START EDITED CODE
}
else if (Object.prototype.toString.call(value1) === '[object Object]' && Object.prototype.toString.call(value2) === '[object Object]'){
result = (value1.value<value2.value)?-1: (value1.value >value2.value)?1:0;
return (multiSortMeta[index].order * result);
//END EDITED CODE
}
else {
result = (value1 < value2) ? -1 : 1;
}
if (value1 == value2) {
return (multiSortMeta.length - 1) > (index) ? (this.multisortField(data1, data2, multiSortMeta, index + 1)) : 0;
}
return (multiSortMeta[index].order * result);
};