jQWidgets Forums

jQuery UI Widgets Forums DataTable Custom sorting

This topic contains 1 reply, has 2 voices, and was last updated by  ivailo 10 years ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Custom sorting #71845

    srmark
    Participant

    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

    Custom sorting #71885

    ivailo
    Participant

    Hi Roland,

    There is no “custom sorting” option about jqxDataTable.
    If you want to use “custom sorting” try jqxGrid as an alternative.

    Best Regards,
    Ivailo Ivanov

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.