简体   繁体   English

DataTable-在第一列中放置选择复选框时出现错误

[英]DataTable - Getting error when putting select checkbox in first column

I know it has been addressed already, but I'm just not getting it to work. 我知道它已经得到解决,但我只是没有使它起作用。 I'm using DataTable Editor with resposnive and serverside. 我正在使用带resposnive和服务器端的DataTable编辑器。 I'm getting an error when I put the checkbox in the first column like: 将复选框放在第一列时出现错误:

js: js:

var table = $('#mytable').DataTable( {
    dom: "rt",
    ajax: {
        url: "/source.php",
        type: "POST",
        data: function (d) { 

        }
    },
    serverSide: true,
    processing: true,
    select: {
        style:    'os',
        selector: 'td:first-child'
    },              
    columns: [
        {
            data: null,
            defaultContent: "",
            className: "select-checkbox",
            orderable: false, 
            targets:   0            
        },                                        
        { data: "logo" },
        { data: "name" },   
        { data: "product" }                                                
    ]                            
} ); 

That's the Error message: 那是错误消息:

DataTables warning: table id=mytable - Unknown field: (index 0) DataTables警告:表ID = mytable-未知字段:(索引0)

php: 的PHP:

Editor::inst( $db, 'table' )
    ->fields(
        Field::inst( 'logo' ),
        Field::inst( 'url' ),       
        Field::inst( 'name' ),
        Field::inst( 'product' )              
    )

... wenn putting in the last column it works: ... wenn将它的最后一栏放进去:

    ...
    columns: [                                        
        { data: "logo" },
        { data: "name" },   
        { data: "product" },
        {
            data: null,
            defaultContent: "",
            className: "select-checkbox",
            orderable: false, 
            targets:   0            
        }                                                              
    ]   
    ...

How can I get the checkbox in the first column? 如何获得第一栏中的复选框? (So column 0) (因此列0)

add this in code 在代码中添加

 $("#table").DataTable({
            'columnDefs': [{
                    'targets': 0,
                    'bSortable': false,
                    'render': function (data, type, full, meta){
                            return '<input type="checkbox"> <label>Checkbox</label>';
                    }
            }]
 })

Here the answer from the author: 这里是作者的回答:

You have server-side processing enabled, and the default ordering is to order on the first column. 您已启用服务器端处理,并且默认排序是在第一列进行排序。 When that happens, DataTables is telling the server to order on the client-side generated column and throws an error. 发生这种情况时,DataTables告诉服务器在客户端生成的列上进行排序,并引发错误。

Use ``order: [[1, 'desc']]` to resolve that. 使用``order:[[1,'desc']]``来解决这个问题。

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

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