Unknown field: (index 7)

Unknown field: (index 7)

User123456User123456 Posts: 57Questions: 15Answers: 0
edited September 2017 in Free community support

I was finishing activation and this error appeared:

DataTables warning: table id=publicationTable - Unknown field: (index 7)

Where is the field index 7?

This is my activation code:

var table = $('#publicationTable').DataTable( {
            lengthChange: true,
        ajax: {
            url: "lib/publicationProcessing.php",
            type: "POST"
        },
        serverSide: true,
            columns: [
                { data: "p.status",
                render: function ( data, type, row ) {
                    var text = "";
                    if (type == "display") {
                        if (data == "1") {
                            text = "<i class='ace-icon fa fa-circle green'></i>";
                        } else {
                            text = "<i class='ace-icon fa fa-circle red'></i>";
                        }
                        data = text
                    }
                    return data;
                }
            },
                { data: "ti.tituloPublicacao" },
                { data: "ty.tipoPublicacao" },
                { data: "p.ano" },
                { data: "p.competencia" },
                { data: "c.razaoSocial" },
                { data: "e.nome" },

                { data: null,
                render: function(data, type, full){
                return '<a data-toggle="modal" data-target="#infoModal" data-id="' + full.p.id_Publication + '" id="getPublication" class="blue"><i class="ace-icon fa fa-search-plus bigger-130"></i></a> <a class="red" href="deletePublication.php?id_Publication=' + full.p.id_Publication + '"><i class="ace-icon fa fa-trash-o bigger-130"></i></a> <a class="orange" href="' + full.p.caminhoArquivo +'" target="_blank"><i class="ace-icon fa fa-download bigger-130"></i></a>';
            }
            }
            ],

            "columnDefs": [ 
            { "orderable": false, "targets": 0 },
            { "orderable": false, "targets": 7 },
            ],
        } );

This is my publicationProcessing:

<?php
include( "php/Datatables.php" );
use
    DataTables\Editor,
    DataTables\Editor\Field;

Editor::inst( $db, 'tbl_publication AS p', 'id_Publication' )
    ->fields(
        Field::inst( 'p.id_Publication' ),
        Field::inst( 'p.status' ),
        Field::inst( 'p.caminhoArquivo' ),
        Field::inst( 'p.ano' ),
        Field::inst( 'p.competencia' ),
        Field::inst( 'ti.tituloPublicacao' ),
        Field::inst( 'ty.tipoPublicacao' ),
        Field::inst( 'c.razaoSocial' ),
        Field::inst( 'e.nome' )
    )
    ->leftJoin( 'tbl_ptitle AS ti', 'p.fk_titulo', '=', 'ti.id_PublicationTitle' )
    ->leftJoin( 'tbl_ptype AS ty', 'p.fk_tipo', '=', 'ty.id_PublicationType' )
    ->leftJoin( 'tbl_company AS c', 'p.fk_empresa', '=', 'c.id_Company' )
    ->leftJoin( 'tbl_employee AS e', 'p.fk_empregado', '=', 'e.id_Employee' )
    ->process($_POST)
    ->json();

And this is the structure of my table:

<table id="publicationTable" class="table table-striped table-bordered table-hover">
                                            <thead>
                                                <tr>
                                                    <th></th>
                                                    <th>Título</th>
                                                    <th>Tipo</th>
                                                    <th>Ano</th>
                                                    <th>Competência</th>
                                                    <th>Razão Social</th>
                                                    <th>Empregado</th>
                                                    <th></th>
                                                </tr>
                                            </thead>
                                        </table>

This question has accepted answers - jump to:

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    { data: null,
                    render: function(data, type, full){
                    return '<a data-toggle="modal" data-target="#infoModal" data-id="' + full.p.id_Publication + '" id="getPublication" class="blue"><i class="ace-icon fa fa-search-plus bigger-130"></i></a> <a class="red" href="deletePublication.php?id_Publication=' + full.p.id_Publication + '"><i class="ace-icon fa fa-trash-o bigger-130"></i></a> <a class="orange" href="' + full.p.caminhoArquivo +'" target="_blank"><i class="ace-icon fa fa-download bigger-130"></i></a>';
                }
                }
    

    That is your index 7.

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Add columns.searchable and columns.orderable to that column object. Set them both to false.

    The issue is that you are using server-side processing, but column index 7 is a client-side generated column, so the server-side knows nowthing about it.

    Allan

  • User123456User123456 Posts: 57Questions: 15Answers: 0
    edited September 2017

    But @allan isn't this what I do in:

    "columnDefs": [
                { "orderable": false, "targets": 0 },
                { "orderable": false, "targets": 7 },
                ],
    

    I see I'm missing columns.searchable. Is there a way to do:

    { "orderable": false, "searchable": false, "targets": 0 },

  • User123456User123456 Posts: 57Questions: 15Answers: 0
    edited September 2017

    @allan the problem only happens in this page. I have two others pages that are almost the same and this doesn't happen. BTW thank you.

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Is there a way to do:
    { "orderable": false, "searchable": false, "targets": 0 },

    Exactly as you have done! Just add the columns.searchable option in to the object and that will hopefully resolve it.

    Allan

This discussion has been closed.