DataTables警告:表格ID = DataTables_Table_0-第0行请求的未知参数“ 4”

时间:2018-11-08 11:52:55

标签: php html

我很久没有问题了。 我使用Web模板进行开发,经常在某些必须显示表格的页面上出现此错误,例如: DataTables warning: table id = DataTables_Table_0 - Requested unknown parameter '4' for row 0,以获取此代码:

<div class="panel panel-flat">
    <table class="table table-bordered table-hover datatable-highlight table-striped">
        <thead>
            <tr class="bg-green-600">
                <th class="text-bold" width="40px">Codes</th>
                <th class="text-bold">Libelle</th>
            </tr>
        </thead>
        <tbody>
        <?php
 
        // Cas sélection compte bancaire
        $sql = "SELECT CODE_CIB, DESCRIPTION_CIB
        FROM CODES_INTERBANCAIRES
        ORDER BY CODE_CIB";
        $req = $DB->query($sql);
        
        while ($d = $req->fetch()) {
        ?>
            <tr>
                <td><?php echo $d['CODE_CIB']; ?></td>
                <td><?php echo $d['DESCRIPTION_CIB']; ?></td>
            </tr>
        <?php
        }
        ?>
        </tbody>
    </table>
</div>

我阅读了有关此错误的建议,但看不到我可能犯的任何错误。我指定在其他页面上它运行完美,在其他启动时出现此错误,当我单击确定按钮时,将显示该页面。 谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

这是链接到模板中我的php页面的datatable js代码

/* ------------------------------------------------------------------------------
*
*  # Advanced datatables
*
*  Specific JS code additions for datatable_advanced.html page
*
*  Version: 1.0
*  Latest update: Aug 1, 2015
*
* ---------------------------------------------------------------------------- */

$(function() {


    // Table setup
    // ------------------------------

    // Setting datatable defaults
    $.extend( $.fn.dataTable.defaults, {
        autoWidth: false,
        columnDefs: [{ 
            orderable: false,
            width: '100px',
            targets: [ 5 ]
        }],
        dom: '<"datatable-header"fl><"datatable-scroll"t><"datatable-footer"ip>',
        language: {
            search: '<span>Filtre:</span> _INPUT_',
            lengthMenu: '<span>Nombre de lignes:</span> _MENU_',
            paginate: { 'first': 'First', 'last': 'Last', 'next': '&rarr;', 'previous': '&larr;' }
        },
        drawCallback: function () {
            $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').addClass('dropup');
        },
        preDrawCallback: function() {
            $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').removeClass('dropup');
        }
    });


    // Datatable 'length' options
    $('.datatable-show-all').DataTable({
        lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]]
    });


    // DOM positioning
    $('.datatable-dom-position').DataTable({
        dom: '<"datatable-header length-left"lp><"datatable-scroll"t><"datatable-footer info-right"fi>',
    });


    // Highlighting rows and columns on mouseover
    var lastIdx = null;
    var table = $('.datatable-highlight').DataTable();
     
    $('.datatable-highlight tbody').on('mouseover', 'td', function() {
        var colIdx = table.cell(this).index().column;

        if (colIdx !== lastIdx) {
            $(table.cells().nodes()).removeClass('active');
            $(table.column(colIdx).nodes()).addClass('active');
        }
    }).on('mouseleave', function() {
        $(table.cells().nodes()).removeClass('active');
    });


    // Columns rendering
    $('.datatable-columns').dataTable({
        columnDefs: [ 
            {
                // The `data` parameter refers to the data for the cell (defined by the
                // `data` option, which defaults to the column being worked with, in
                // this case `data: 0`.
                render: function (data, type, row) {
                    return data +' ('+ row[3]+')';
                },
                targets: 0
            },
            { visible: false, targets: [ 3 ] }
        ]
    });



    // External table additions
    // ------------------------------

    // Add placeholder to the datatable filter option
    $('.dataTables_filter input[type=search]').attr('placeholder','Rechercher...');


    // Enable Select2 select for the length option
    $('.dataTables_length select').select2({
        minimumResultsForSearch: "-1"
    });
    
});