I have two tables in View. First one 'menuTable' and the other 'confirmTable' . When I click a button in a Row from 'menuTable' , a row in 'confirmTable' is to be added with test data. I have a reference to :
<script src="~/Content/js/dataTables.bootstrap.min.js"></script>
<script src="~/Content/js/jquery.dataTables.min.js"></script>
My view for '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>
After I click on add button 'addToCurrentOrders()' function is called and function is:
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();
}
When I inspect , I get the following error message:
Uncaught Error: Syntax error, unrecognized expression: <input type='text' value='1'/>
Try changing $('#confirmTable').DataTable().row(newRow).add.draw();
to below.
$('#confirmTable').DataTable().row.add(newRow).draw();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.