Quantcast
Channel: Free community support — DataTables forums
Viewing all articles
Browse latest Browse all 35470

custom sorting, group on secondary column

$
0
0

I need to know how group a custom sort based on a secondary column.

I want to be able to group my sort on the value in the second column, then sort like normal based on that grouping.

Here are my sorting functions:

jQuery.fn.dataTableExt.oSort['sortFed-asc'] = function (x, y) {
    if (x === "Federal") return -1; // keep this row at top
    if (y === "Federal") return 1; // keep this row at top

    var stateName1 = $('label[id*=_label_]', '<div>' + x + '</div>').text();
    var stateName2 = $('label[id*=_label_]', '<div>' + y + '</div>').text();

    return ((stateName1 < stateName2) ? -1 : ((stateName1 > stateName2) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['sortFed-desc'] = function (x, y) {
    if (x === "Federal") return -1; // keep this row at top
    if (y === "Federal") return 1; // keep this row at top

    var stateName1 = $('label[id*=_label_]', '<div>' + x + '</div>').text();
    var stateName2 = $('label[id*=_label_]', '<div>' + y + '</div>').text();

    return ((stateName1 < stateName2) ? 1 : ((stateName1 > stateName2) ? -1 : 0));
};

$("#myTable").dataTable({
    "bAutoWidth": false,
    "bFilter": false,
    "paging": false,
    "info": false,
    "scrollY": "300px",
    "scrollCollapse": false,
    "bSortCellsTop": true,
    "aoColumns": [
        { "sWidth": "60px", "sType": "sortFed", "sClass": "agency_col" },
        { "sWidth": "30px", "sType": "sortFed", "sClass": "status_col" }
    ]
});

Viewing all articles
Browse latest Browse all 35470

Latest Images

Trending Articles



Latest Images