最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to add data inside datatable using jquery? - Stack Overflow

matteradmin7PV0评论

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);     
}; 

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);     
}; 
Share Improve this question edited Jul 9, 2014 at 7:28 user3817023 asked Jul 8, 2014 at 22:24 user3817023user3817023 591 gold badge2 silver badges10 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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);
     };

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

Post a comment

comment list (0)

  1. No comments so far