[英]How to add html checkbox on Datable without adding additional columns
I have my data as json key value pairs in an array.我的数据作为数组中的 json 键值对。
$(document).ready(function () {
var table = $("#main").DataTable({
columns: [{
"data": "ProductNumber",
"title": "ProductNumber"
},
{
"data": "ReceivingDate",
"title": "ReceivingDate"
}]
I want to add checkboxes so that users can select some rows.我想添加复选框,以便用户可以选择一些行。
columnDefs: [{
targets: 0,
searchable: false,
orderable: false,
className: 'dt-body-center',
render: function (data, type, full, meta) {
return '<input type="checkbox" name="id[]" value="' +
$('<div/>').text(data).html() + '">';
}
}]
I found the columnDef
example from the DataTable
website.我从
DataTable
网站找到了columnDef
示例。 The issue is, it is told to render this checkbox on column 0 which replaces my productnumber
column.问题是,它被告知在替换我的
productnumber
列的第 0 列上呈现此复选框。 And I can't add an empty column as my json data has the exact number of data as the columns have.而且我无法添加空列,因为我的 json 数据与列的数据数量完全相同。 Are there any other ways I can achieve this?
我还有其他方法可以实现这一目标吗?
您可以将该复选框插入到现有单元格中,例如 Id Columns。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.