Click here to Skip to main content
16,019,983 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following data table, where status contains checkboxes that I want to be able to sort on that column

$('#aMG_permissionTable')
    .dataTable({

        "bJQueryUI": true,
        "bPaginate": false,
        "sScrollY": "440",
        "bAutoWidth": true,
        "bFilter": true,
        "bInfo": true,
        "bSort": true,
        "aoColumns": [
            { "mData": "PermissionName" },
            { "mData": "PermissionWithDescription" },
            { "mData": "PermissionGroupWithDescription" },
            { "mData": "Status" }
            //{ "mData": "Status", "sSortDataType": "dom-checkbox" }
        ],
        "aoColumnDefs": [
            { "bVisible": false, "aTargets": [0] },
            // { "bSortable": false, "aTargets": [ 3] },
            { "sSortDataType": "dom-checkbox", "aTargets": [ 3 ] }
        ],
        "sPaginationType": "full_numbers",
        "aaSorting": [[ 0, "asc"]]
    });


What I have tried:

I have tried the following, but the error is empty, when debugging it does not even enter the each loop.

/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function  ( oSettings, iColumn )
{
	var aData = [];
	$( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
		console.log(this);
		aData.push( this.checked==true ? "1" : "0" );
	} );
	//console.log(aData);
	return aData;
};
Posted

1 solution

$.fn.dataTableExt.afnSortData['dom-checkbox'] = function  ( oSettings, iColumn, iVisibleColumn ) {
	return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr) {
		return $(tr).find('td:eq(2) input').prop('checked') ? '1' : '0';
	});
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900