Hello,
I saw that there is custom sorting for jqxGrid on this page:
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/#demos/jqxgrid/customsorting.htm
I have tried to make this work with jqxDataTable, but it doesn’t work for me. My code uses the dataadapter with local data:
var source = {localData: data, dataType: "array", sortcolumn: 'name', sortdirection: 'asc', sort: customsortfunc};
var dataAdapter = new $.jqx.dataAdapter(source);
and the dataAdapter variable is given to the datatable as source.
When I sort the table by one of the columns the function given in the source, customsortfunc
fires, and runs properly, but it appears that the result cannot be given to the datatable, my sorting function:
function customsortfunc(column, direction) {
if (typeof direction == "undefined" || (column != "currentUptime" && column != "totalUptime")) {
return;
}
var varName = "currentUptimeOriginal";
if (column == "totalUptime") {
varName = "totalUptimeOriginal"
}
var sortData = source.localData;
sortData.sort(function (a, b) {
var aValue = parseInt(a[varName]);
var bValue = parseInt(b[varName]);
console.log(aValue, bValue, aValue == bValue ? 0 : (aValue < bValue ? -1 : 1));
return aValue == bValue ? 0 : (aValue < bValue ? -1 : 1);
});
if (direction === false) {
sortData.reverse();
}
source.localData = sortData;
var dataAdapter = new $.jqx.dataAdapter(source);
$("#userDevicesBox").jqxDataTable({source: dataAdapter});
console.log(column, direction, sortData);
}
At the end I tried to call different functions with multiple combinations on the datatable, such as clear, updateBoundData, render, refresh, and building up the dataadapter again as you can see in my latest code, but none of them showed the expected result on the table.
Thanks in advance for your help,
Roland