DataTable is a plugin of JQ, specific how to use and the role of the parameters of the official website have, I will not say.
When we initialize a table with a DataTable, we change the contents of the table, and then we want to re-initialize the new table again, what should we do?
To give an example:
I use backbone to write the front-end JS code:
var App.dt = {
Sdom: ' < row ' >< ' pull-right search ' f>rt ' +
' < row ' < ' col-sm-12 ' < ' pull-left ' i> ' +
' < ' Pull-left "l><" Pull-right "p><" Clearfix ">>>d",
' bprocessing ': true,
' Bsort ': false,
' Bretrieve ': true,
' Blengthchange ': true,
' Idisplaylength ': 10,
' Alengthmenu ': [10, 15, 20, 30],
' Bdestroy ': true
};
var dttable = $ (' #example '). DataTable (APP.DT);
After initialization, we get the desired effect, and then we add a record to the table, that is, adding a TR, and then the DataTable initialization of this table will not work, then our table will be deformed,
The records that would have been paginated as required will all be displayed on the first page at once.
So my solution is:
if ($ (' #example '). Hasclass (' dataTable ')) {
dttable = $ (' #example '). dataTable ();
dttable. fncleartable (); Clear the table, please.
dttable. Fndestroy (); Restore the initialized DataTable
}
Insert all new data into $ (' #example ')
if (app.xmCol.length!== 0) {
App.xmCol.each (This.addone, this);
}
$ (' #example '). dataTable (APP.DT);
After this process, whether we add or delete the table, our DataTable can be displayed and paginated.
Purely personal practice experience, if you have other methods, also hope to share.
Use of Fndestroy and fncleartable in DataTable