DataTables remove row button

前端 未结 3 790
感情败类
感情败类 2021-01-07 06:56

I am trying to have my script delete the row completely once the \"locatebutton\" has been pressed. I have the following code however I cannot seem to get it working right.

3条回答
  •  死守一世寂寞
    2021-01-07 07:25

    I know this is an old post, but for further references, the proposed answers won't work for responsive tables which rows have been splitted. In that case, we will need something like :

    $('#example').on("click", "button", function(){
      var td = $(this).closest("tr"); 
      if (td.hasClass("child")) {td.prev('.parent').remove();}
      td.remove();
    });
    

    Edit

    Better yet (I think) :

    $('#example').on("click", "button", function(){
      var table = $(button).closest("table").DataTable();
      table.cell( {focused:true} ).row().remove();
      table.draw();
    

提交回复
热议问题