Skip to content Skip to sidebar Skip to footer

How To Load Extra Javascript In Datatable Server Side Processing?

I am using Datatable.net 1.10, with server processing. It is all good and working fine, but I can't get other javascript to work in the datatable. For example I was using tippy.js

Solution 1:

You have to call tooltip after datatables complete its initialization, you can use fnInitComplete callback to do that:

$(document).ready( function() {

  $('#example').dataTable({

    ...,

    "fnInitComplete": function(oSettings, json) {
      alert( 'DataTables has finished its initialisation.' );
      // call tooltip heretooltip('.tip', 'ehs');
    }

  });

});

Because you are using datatables and tooltip in 2 separate functions you can use callbacks to call them in order:

myDataTableAjax_Accident function:

function myDataTableAjax_Accident(id, actionURL, done) {

    ...,

    "fnInitComplete": function(oSettings, json) {

        done();

    }

}

And then in your View you can pass done parameter as a function and then call tooltip like this:

<script>
    $(document).ready(function () {
        myDataTableAjax_Accident('tblAccident', '@Url.Action("DatatableServerSideIndex")', function() {
            tooltip('.tip', 'ehs');
        });
    });
</script>

Post a Comment for "How To Load Extra Javascript In Datatable Server Side Processing?"