How to add data inside datatable using jquery?

拜拜、爱过 提交于 2020-01-05 08:28:09

问题


I want to do is make a function that add data in my table and have a delete function in action column using jquery.

My problem is I'm having trouble putting my input values in the table using jquery.

  function Add(){
    $("#myTable tbody").append(
        "<tr>"+
        "<td><input type='text'/></td>"+
        "<td><input type='text'/></td>"+
        "<td><input type='radio'/></td>"+
        "<td><button class='btnDelete>Delete</button></td>"+
        "</tr>");   
        $(".Save").bind("click", Save);     
}; 

回答1:


If you are using datatable, then use datatable 'fnAddData' function for adding new row instead of jquery append function. Check the following code,

    oTable = $('#myTable').dataTable();

     function Add(){

          var data = [
             $('#input1').val(),
             $('#input2').val(),
             $('#input3').val(),
             $('#input4').val()
          ];


          oTable.fnAddData(data);
     };



回答2:


Here is legacy documentation for version 1.9.x

How to add row for version 1.9.x and below

Note: You better start using new version of data table 1.10.x



来源:https://stackoverflow.com/questions/24642456/how-to-add-data-inside-datatable-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!