简体   繁体   English

从表值向Datatable添加新行?

[英]Add new row to Datatable from table values?

I have a Datatable with information, and a fieldset with a table full of text inputs. 我有一个带有信息的数据表,以及一个带有充满文本输入表的字段集。 The user should be able to add new rows according to the information values, but these rows are not correctly adding. 用户应该能够根据信息值添加新行,但是这些行未正确添加。 Clearly the tr is being cloned and added (emptied where needed), the corresponding values are appending but the pagination is not being updated for Datatables. 显然,tr正在克隆和添加(在需要时为空),正在附加相应的值,但不会为Datatable更新分页。 I cannot figure out how to correctly use .fnAddData() to get the job done here. 我无法弄清楚如何正确使用.fnAddData()在这里完成工作。 On top of that, I don't know how to go about the "Permissions" column - getting checkboxes to convert to text for the table. 最重要的是,我不知道如何处理“权限”列-获取复选框以将表格转换为文本。 Any ideas? 有任何想法吗? Thanks in advance. 提前致谢。

http://jsfiddle.net/BWCBX/28/ http://jsfiddle.net/BWCBX/28/

jQuery jQuery的

$('#addRow').click(function () {
    var tbody = $('#example tbody');
    var tr = tbody.find('tr:first').clone();
    tr.find('td:first').text($(".engine").val());
    tr.find('td:eq(1)').empty();
    tr.find('td:eq(2)').empty();
    tr.find('td:eq(3)').text($(".version").val());
    tr.find('td:eq(4)').empty();
    tr.appendTo(tbody);
});

There are good examples on how to use fnAddData in the API docs . API文档中提供了有关如何使用fnAddData良好示例。

I have rewritten your JS according to example provided in docs. 我已经根据文档中提供的示例重写了您的JS。 I've extracted checkboxes checking into separate function to mantain high readability. 我已经将复选框提取为单独的功能,以保持较高的可读性。 The updated fiddle is here . 更新的小提琴在这里

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

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