execute JS after sorting

execute JS after sorting

havahava Posts: 11Questions: 0Answers: 0
edited November 2011 in General
Hi All,

I have bumped with problem,
my table cells have java script code. When page loading, JS executes but after sorting, when it loads new data, no actions from JS though I see it via FireBug ( no errors ). How to make it execute JS after data reloading?

Thanks

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    fnDrawCallback might be what you want - you can check the oSettings.bSorted flag if you want to execute something only on sorting).

    How is the table loading new data?

    Allan
  • havahava Posts: 11Questions: 0Answers: 0
    edited November 2011
    Here is setting code
    (Sorry, I didnt write this code, just fixing exxisting code and I am not familiar with dataTable, if you can, please explain me 'on fingers' where to put and how to use. Thank you! )
    [code] $js = '
    oTable = $(".store_datatable").dataTable({
    "sPaginationType": "full_numbers",
    "bLengthChange": false,
    "aaSorting": '.$this->EE->javascript->generate_json(array($default_sort), TRUE).',
    "bFilter": false,
    "bAutoWidth": false,
    "iDisplayLength": '.$perpage.',
    "aoColumnDefs" : '.$this->EE->javascript->generate_json($col_defs, TRUE).',
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "'.html_entity_decode(BASE.AMP.STORE_CP.AMP.'method='.$ajax_method).'",
    "fnServerData": function (sSource, aoData, fnCallback) {
    var extraData = $("#filterform").serializeArray();
    for (var i = 0; i < extraData.length; i++) {
    if (extraData[i].name == "perpage") {
    $(".store_datatable").dataTable().fnSettings()._iDisplayLength = parseInt(extraData[i].value);
    }
    aoData.push(extraData[i]);
    }
    $.getJSON(sSource, aoData, fnCallback);
    },
    "oLanguage": {
    "sZeroRecords": "'.$this->EE->lang->line('no_entries_matching_that_criteria').'",
    "sInfo": "'.lang('dataTables_info').'",
    "sInfoEmpty": "'.lang('dataTables_info_empty').'",
    "sInfoFiltered": "'.lang('dataTables_info_filtered').'",
    "sProcessing": "'.lang('dataTables_processing').'",
    "oPaginate": {
    "sFirst": "",
    "sPrevious": "",
    "sNext": "",
    "sLast": ""
    }
    },
    "fnRowCallback": function(nRow,aData,iDisplayIndex) {

    $(nRow).addClass("collapse");
    return nRow;
    }
    });
    oSettings = oTable.fnSettings();
    oSettings.oClasses.sSortAsc = "headerSortUp";
    oSettings.oClasses.sSortDesc = "headerSortDown";
    '; [/code]
  • havahava Posts: 11Questions: 0Answers: 0
    edited November 2011
    -
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    You need to use name/value pairs as shown in this example: http://datatables.net/release-datatables/examples/server_side/custom_vars.html . I would suggest using fnServerParams (new in 1.8.2) as shown in the example to add the extra data to send to the server - makes life much easier :-)

    Allan
  • havahava Posts: 11Questions: 0Answers: 0
    will be drilling it down. thank you,
This discussion has been closed.