【发布时间】:2020-12-20 15:45:09
【问题描述】:
我无法在表格中添加复选框,我尝试了很多东西,但一切都是徒劳的
jQuery 代码:
$(document).ready(function() {
var total = [];
$.ajax({
url: 'user.json',
dataType: 'json',
success: function(json) {
// get the `airport` array
var device = json.siteList;
var j = 1;
// loop through the array to populate your list
$.each(device, function(i, sites) {
// console.log(sites.siteName)
// $('#data_table').append("<tr>" + "<td>" + sites.siteName + "</td>" + "</tr>");
$.each(sites.deviceList, function(i, values) {
item = {}
item['siteName'] = sites.siteName;
item["deviceName"] = values.deviceName;
item["count"] = values.count;
total.push(item);
});
});
$('#rpa_table').DataTable(
columnDefs: [{
orderable: false,
className: 'select-checkbox',
targets: 0
}],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [
[1, 'asc']
], {
"aaData": total,
"aoColumns": [{
"sTitle": "Site",
"mData": "siteName"
},
{
"sTitle": "Cabinet",
"mData": "deviceName"
},
{
"sTitle": "Count",
"mData": "count"
},
],
});
}
});
// Handle click on "Select all" control
// Handle click on "Select all" control
$('#checkall').on('click', function() {
// Check/uncheck all checkboxes in the table
var rows = table.rows({
'search': 'applied'
}).nodes();
$('input[type="checkbox"]', rows).prop('checked', this.checked);
});
});
图片附在上面, 检查了很多网站没有线索每次都发生相同的错误 任何帮助将不胜感激 在此先感谢........
【问题讨论】:
-
大概,您应该将一个对象传递给 DataTable 构造函数。对象包含在
{}中。例如$('#rpa_table').DataTable({ columnDefs: [] }) -
ypeError: Cannot read property 'aDataSort' of undefined 这个错误来了
标签: jquery