Use of Fndestroy and fncleartable in DataTable

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.