Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture event after sorting on datatable with jquery

I've an issue with a datable (http://www.datatables.net), jQuery and Firefox.

I've a jQuery datatable (id="equipmentList") with a button above:

<html:button styleId="deleteButton" property="delete" value="<%= buttonDelete %>" disabled="disabled" />

When i'm sorting a column on the datatable, i want to disable a button (the button deleteButton), so I wrote this code :

$('#equipmentList th').click( function() {
    hideButtonEditAndDelete();
});

function hideButtonEditAndDelete() {
    $("#modifyButton").attr("disabled", "disabled");
    $( "#deleteButton" ).attr("disabled", "disabled");

//fix for firefox

if($.browser.mozilla){
    $("#modifyButton").addClass('ui-state-disabled');
    $("#deleteButton").addClass('ui-state-disabled');
}}

Everything goes well until the sort is ending because, after, my button is enabled by jQuery; or something else. so I'm looking for capture event at the end of sorting order to disable my button

like image 404
magnetictank Avatar asked Jan 12 '11 09:01

magnetictank


1 Answers

There is a callback that is made every time that the table is redrawn and can be accessed on the fnDrawCallback:

$('#someTable').dataTable({
        "fnInitComplete": function() {
            // after table is intialised do something here
        },
        "fnDrawCallback": function() {
            // after table is redrawndo something here
            console.log("redrawn");
        },
        "bDestroy": true,
        "bAutoWidth": false,
        "bPaginate": false,
        "sScrollY": "242px",
        "bLengthChange": false,
        "bInfo": false,
        "bFilter": false,
        "aaSorting": [[2, 'asc']],
        "aoColumns": [
            { "sSortDataType": "dom-checkbox", "sWidth": "3%" },
            { "bSortable": true, "sWidth": "8%" },
            { "bSortable": true, "sWidth": "10%" },
            { "bSortable": true, "sWidth": "15%" },
            { "bSortable": true, "sWidth": "8%" },
            { "bSortable": true, "sWidth": "9%" },
            { "bSortable": true, "sWidth": "6%" },
            { "bSortable": false, "sWidth": "2%" },
            { "bSortable": false, "sWidth": "7%" },
            { "bSortable": false, "sWidth": "13%" },
            { "bSortable": false, "sWidth": "2%" },
            { "bSortable": false, "sWidth": "7%" },
            { "bSortable": false, "sWidth": "10%" }
        ]
    });

More info on callbacks here:

http://datatables.net/usage/callbacks

like image 184
RyanP13 Avatar answered Sep 28 '22 06:09

RyanP13