简体   繁体   中英

can't sort newly added rows to html table

I have an html table with sorting capabilities for each column. I want to add new items to the table when I press the submit buttton, and i want to be able to sort with those newly added rows. but right now they dissapear every time I try to sort with the new rows. Is there some way to modify the javascript so the newly added rows stay?

(jsfiddle link uses external script like jquery and styling, so code cant be ran in github browser)

need code example to accompany url

http://jsfiddle.net/martinradio/eqL7pc23/5/

I had a quick look on the documentation and I think you should use the methods provided on Datatable's documentation:

  1. https://datatables.net/examples/api/add_row.html - to add new rows
  2. https://datatables.net/reference/api/draw() - to redraw the table

To add table to your table you should need only to do something like:

var t =  $('#dtBasicExample').DataTable();
t.row.add(["adam", "prince", "texas", "44", "2011/03/30", "$14"]);
t.row.add(["Bob", "prince", "texas", "44", "2011/03/30", "$14"]);
t.draw(false);

Please let me know if it worked for you.

André

Please use this link to resolve issue : 

http://jsfiddle.net/s14q6rah/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM