簡體   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