superted superted - 1 year ago 228
jQuery Question

jquery datatable row.add with button and input box

Hi I am new to jquery and trying to dynamically add row dynamically using the button from another datatable row.

Is there any easy way that using the row.add() function to create a row with button and input text like the below tr ?

<td> <button type="button" class="btn green btn-xs select-row" data-id="7" data-includeTax="N">btn</button>
<td><input type="text" ></td>

enter image description here
im trying to call function similar to below on onclick event

saleDetailDT.row.add([..... ? ]).draw();

Answer Source

Try something like this:

     var table = $('#dataTables').DataTable();
     table.row.add(['<button type="button" class="btn green btn-xs select-row" data-id="7" data-includeTax="N">btn</button>','1','2','<input type="text">','3']).draw();
     // table.row.add([first_td_html_of_tr,second_td-html_of_tr,third_td_html_of_tr,...nth td_html_of_tr]).draw();


And dont forget to give your table id="datatables" as below.

<table id ="datatables">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download