Skip to content Skip to sidebar Skip to footer

Bootstrap Datatable Is No Longer Functioning After Loading Content Via Ajax

Before some one says its a duplicate question, i know it is. I've just not been able to find anyone's script that looks similar to mine and as i'm completely new to JavaScript and

Solution 1:

I suggest creating the table structure in HTML or PHP (not Javascript). Then load the data into the table with ajax. Those DOM elements are not readily available to javascript unless the event to create the elements is bound to an element that already exists like body or document or some other parent element of the table.

UPDATE:

I personally don't have much experience with DataTables plugin. So the plugin will automatically create your DOM elements (table structure) based on either the data object returned from ajax or by properties you specify. DataTables does use jQuery's ajax() method to make ajax calls however you should not override the success callback. There is a proper way to use their API when making ajax calls as specified in the documentation. There is also a proper way to reload data on an interval to refresh your tables.

Please check out this fiddle.

The ajax url, method, data properties must of course be updated to fit your application (this was the only way to simulate ajax call on jsFiddle. Please note you will have to have properly formatted JSON.

Solution 2:

Did you tried to explicitly set pagelength property on Datatables?

$('#datatable').dataTable( {
  "pageLength": 50
} );

Post a Comment for "Bootstrap Datatable Is No Longer Functioning After Loading Content Via Ajax"