[英]Load DataTables dynamically in JQuery tabs
I am planning to use JQuery Datatables in one of my project, so i decided to do a POC to ensure that everything is planned. 我计划在我的一个项目中使用JQuery Datatables,因此我决定进行POC以确保所有内容都已计划好。
I build a table where i will be printing the values from my Object which will be received as a JSON during my further development. 我建立了一个表,在该表中我将打印来自我的对象的值,这些值将在以后的开发中作为JSON接收。 But i am getting an AJAX error for the id i was going to print the data.
但是我正在获取要打印数据的ID的AJAX错误。
I have uploaded the code on JSFiddle ! 我已经在JSFiddle上上传了代码!
HTML HTML
<div id="tab-customers">
<table id="customers-table" class="display general-table" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Phone</th>
<th>Gender</th>
<th>City</th>
<th>Country</th>
</tr>
</thead>
</table>
</div>
JQuery JQuery的
$(".tabs").click(function() {
var source = $(this).data("source");
var tableId = $(this).data("table");
initiateTable(tableId, source);
});
function initiateTable(tableId, source) {
var table = $("#" + tableId).DataTable({
"ajax": source,
order: [],
columnDefs: [{
orderable: false,
targets: [0]
}],
"destroy": true,
"bFilter": true,
"bLengthChange": false,
"bPaginate": false
});
}
initiateTable("customers-table", "customers");
$("#dynamic-tabs").tabs();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.