简体   繁体   English

数据表输入与行相处

[英]Datatable inputs get along with row

I have added inputs for only 10 columns in my datatable and trying to save with button click.我在数据表中仅添加了 10 列的输入,并尝试通过单击按钮进行保存。 Below is my code下面是我的代码

 $('#tblFormBtn').click( function() {
   let datas = tblListUpload.$("input").serializeArray();
 });

it's getting all the inputs in separate array values.它以单独的数组值获取所有输入。 Is it possible to get that array by row?是否可以逐行获取该数组?

Update: working sample http://live.datatables.net/bucawete/1/ Update:工作样本http://live.datatables.net/bucawete/1/

You can map each row to create a serializeArray , here's an example:您可以map创建一个serializeArray ,这是一个示例:

 const table = $('#example').DataTable(); const data = table.rows().nodes().map((e) => $(e).find('input, select').serializeArray()); console.log(data.toArray());
 <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" /> <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script> <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Name</th> <th>Age</th> <th>Position</th> <th>Office</th> </tr> </thead> <tfoot> <tr> <th>Name</th> <th>Age</th> <th>Position</th> <th>Office</th> </tr> </tfoot> <tbody> <tr> <td>Tiger Nixon</td> <td><input type="text" id="row-1-age" name="row-1-age" value="61"></td> <td><input type="text" id="row-1-position" name="row-1-position" value="System Architect"></td> <td> <select size="1" id="row-1-office" name="row-1-office"> <option value="Edinburgh" selected="selected">Edinburgh</option> <option value="London">London</option> <option value="New York">New York</option> <option value="San Francisco">San Francisco</option> <option value="Tokyo">Tokyo</option> </select> </td> </tr> <tr> <td>Garrett Winters</td> <td><input type="text" id="row-2-age" name="row-2-age" value="63"></td> <td><input type="text" id="row-2-position" name="row-2-position" value="Accountant"></td> <td> <select size="1" id="row-2-office" name="row-2-office"> <option value="Edinburgh">Edinburgh</option> <option value="London">London</option> <option value="New York">New York</option> <option value="San Francisco">San Francisco</option> <option value="Tokyo" selected="selected">Tokyo</option> </select> </td> </tr> <tbody> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM