繁体   English   中英

如何在不添加其他列的情况下在 Datable 上添加 html 复选框

[英]How to add html checkbox on Datable without adding additional columns

我的数据作为数组中的 json 键值对。

$(document).ready(function () {
        var table = $("#main").DataTable({
            columns: [{
                    "data": "ProductNumber",
                    "title": "ProductNumber"
                },
                {
                    "data": "ReceivingDate",
                    "title": "ReceivingDate"
                }]

我想添加复选框,以便用户可以选择一些行。

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() + '">';
                }
            }]

我从DataTable网站找到了columnDef示例。 问题是,它被告知在替换我的productnumber列的第 0 列上呈现此复选框。 而且我无法添加空列,因为我的 json 数据与列的数据数量完全相同。 我还有其他方法可以实现这一目标吗?

您可以将该复选框插入到现有单元格中,例如 Id Columns。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM