SoFunction
Updated on 2025-04-10

Layui click on the data table to add or delete a row

Data table

t2 = {
      elem: '#test2',
      data: tableData2,
      page: false,
      width: $().width()-50,
      cols: [[
        {type:'checkbox',field:'id'},
        {field:'cstMoldNo', title: 'Customer Model Number',edit:'text'},
        {field:'cstProdName', title: 'Product Name',edit:'text'},
        {field:'material', title: 'Product Materials',edit:'text'},
        {field:'firstTryDate', title: 'Verification Date',edit:'text'},
        {field:'deliveryDate', title: 'delivery date',edit:'text'},
        {field:'unit', title: 'unit',edit:'text'},
        {field:'count',   title: 'quantity',edit:'text'},
        {field:'upTax',   title: 'Tax included unit price',edit:'text'},
        {field:'priceTax',    title: 'Tax included',edit:'text'},
        {field:'remark', title: 'Remark',edit:'text'},
        {fixed: 'right', title: 'operate',width: '10%',align: 'center',toolbar: '#barDemo'}
      ]]
    };

Click to add a line

 ('addsome2').addEventListener('click',function (data) {
      var oldData = ["test2"];
      var data1={};
      (data1);
      ('test2',{data : oldData});
    });

Click to delete a line

 if( === "del"){
        ("Are you sure you want to delete it?",{btn:['Yes, I'm sure','I'll think about it again']},
            function(){
              var oldData = ["test2"];
              (('index'),1);
              ("Delete successfully",{time: 10},function(){
                ('test2',{data : oldData});
              });
            }
        )
      }

The above example of adding or deleting a row in the layui click data table is all the content I share with you. I hope you can give you a reference and I hope you can support me more.