Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables reInitialization (jQuery)

When I load my page in first place there nothing in the table and the datatable is not initializated, after a few interactions rows are added and when all rows are added (with ajax calls) I init the datatable this way:

oTable = $('#table).dataTable( {
            "bJQueryUI": true,
            "bSortClasses": false,
            "sDom":'T<"clear">',
            "sPaginationType": "full_numbers",
            "sDom": 'T<"clear"><"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>'
        } );

The problem is I want to be able to clear that table and keep on adding stuff in the html and then reInit the table from that source code without using fnAddData.

Any ideas?

Thank you!

like image 426
Pierluc Avatar asked Jul 08 '10 20:07

Pierluc


People also ask

How to clear DataTable in jQuery?

function destroy( [ remove ] ) When set to true , as of v1. 10.8, DataTables will use the jQuery . remove() method to remove the table from the page - this results in any events that are bound to the table elements being automatically removed by jQuery.

How do you know if DataTable is initialized?

isDataTable() method provides the ability to check if a table node is already a DataTable or not. It can be accessed at any time, even before any DataTable has been created on the page. isDataTable() is a function of $. fn.

What is fnDestroy?

1) fnDestroy does a number of things to return the table to its pre-datatables state. In at least one use here, we want to destroy the table entirely, and are calling fnDestroy to make sure its data is freed.


1 Answers

Calling $('#table').dataTable().fnDestroy(); will clear the table of dataTable code and allow you to manipulate the table, and then call dataTable on it again.

like image 192
shmuel613 Avatar answered Sep 18 '22 05:09

shmuel613