繁体   English   中英

无法使用jQuery DataTables在DataTable中添加行

[英]unable to add row in DataTable using jquery datatables

我在View中有两个表。 第一个'menuTable'和另一个'confirmTable'。 当我单击“ menuTable”中“ Row”中的按钮时,“ confirmTable”中的一行将与测试数据一起添加。 我有一个参考:

<script src="~/Content/js/dataTables.bootstrap.min.js"></script>
<script src="~/Content/js/jquery.dataTables.min.js"></script>

我对“ confirmTable”的看法:

<table id="confirmTable" class="table table-bordered table-striped dataTable">
    <thead>
        <tr role="row">
            <th class="sorting_desc" width="180px" rowspan="1" colspan="1" tabindex="0">Menu Item Name</th>
            <th class="sorting" rowspan="1" colspan="1" tabindex="1" width="220px;" aria-label="Description: activate to sort column ascending">Description</th>
            <th class="sorting" rowspan="1" colspan="1" tabindex="2" width="220px;">Rate </th>
            <th class="sorting" rowspan="1" colspan="1" tabindex="3" width="220px;">Quantity</th>
            <th class="sorting" rowspan="1" colspan="1" width="220px;">Total</th>
            <th class="sorting" rowspan="1" colspan="1" tabindex="4" width="220px;">Action</th>
        </tr>
    </thead>
    <tbody>
        <!--add row after clicking on menu items-->
    </tbody>
</table>

在我单击添加按钮后,调用了“ addToCurrentOrders()”函数,该函数为:

function addToCurrentOrders() {

    //add to confirm table
    var currentRowNumber = $('#confirmTable').DataTable().data().length;
    var newRow = new Array(6);
    newRow[0] = "<input type='text' value='1' />";

    newRow[1] = "<input type='text' value='2' />";
    newRow[2] = "<input type='text' value='3' />";
    newRow[3] = "<input type='text' value='4' />";
    newRow[4] = "<input type='text' value='5' />";

    // Embed hidden fields in actionBtnTd
    var actionBtnsString = "<input type='text' id='inputMenuItemID' name='data' value='10'/>";
    newRow[5] = actionBtnsString;
    $('#confirmTable').DataTable().row(newRow).add.draw();

}

当我检查时,收到以下错误消息:

Uncaught Error: Syntax error, unrecognized expression: <input type='text'  value='1'/> 

尝试更改$('#confirmTable').DataTable().row(newRow).add.draw(); 到下面。

$('#confirmTable').DataTable().row.add(newRow).draw();

暂无
暂无

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

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