DataTable Editor - Getting error when putting select checkbox in first column

DataTable Editor - Getting error when putting select checkbox in first column

CapamaniaCapamania Posts: 233Questions: 81Answers: 5
edited April 2018 in Editor

I'm getting an error when I put the checkbox in the first column like:

js:

    var table = $('#mytable').DataTable( {
        dom: "rt",
        ajax: {
            url: "/source.php",
            type: "POST",
            data: function (d) { 
            
            }
        },
        destroy: true,
        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)

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:

        ...
        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)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Answer ✓

    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.

    Use ``order: [[1, 'desc']]` to resolve that.

    Allan

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5

    Great thanks!

This discussion has been closed.