如何在Datable上添加html复选框而不添加其他列 [英] How to add html checkbox on Datable without adding additional columns

查看:123
本文介绍了如何在Datable上添加html复选框而不添加其他列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据作为数组中的json键值对存储.

I have my data as json key value pairs in an array.

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

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

I found the columnDef example from the DataTable website. The issue is, it is told to render this checkbox on column 0 which replaces my productnumber column. And I can't add an empty column as my json data has the exact number of data as the columns have. Are there any other ways I can achieve this?

推荐答案

您可以将复选框插入到ID列之类的现有单元格中.

You can insert the checkbox into an existing cell like Id Columns.

这篇关于如何在Datable上添加html复选框而不添加其他列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆