本文介绍了DataTables警告:表ID = table_especie-请求的未知参数'0',用于第0行,第0列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题被问了数百遍,但是我认为我的案子非常具体,它需要一个知道jQuery的人来帮助,或者至少以前见过这个人!

I know this was asked hundreds of times, but I think my case is very specific and it needs someone who knows jQuery to help, or at least has seen this before!

我有这段代码来建立一个名为"especie:

I have this code to build a table called "especie:

HTML

<table class="table" id="table_especie">
     <thead>
      <tr>
       <th></th>
       <th></th>
      </tr>
     </thead>
     <tbody>
     </tbody>
</table>

脚本JS:

var tableEspecie= $('#table_especie').DataTable({
    "paging":   false,
    "info":     false,
    "order": [
        [2, "asc" ],
        [3, "asc"],
        [1, "asc"]
    ],
    "columnDefs": [
        { "visible": false, "targets": 0 },
        { "visible": false, "targets": 2 },
        { "visible": false, "targets": 3 }
    ],

    "drawCallback": function () {
        var api = this.api();
        var rows = api.rows( {page:'current'} ).nodes();
        var last=null;

        api.column(2, {page:'current'} ).data().each( function ( especie, i ) {
            if ( last !== especie) {
                $(rows).eq( i ).before(
                    '<tr class="especie info"><td colspan="4">'+especie+'</td></tr>'
                );

                last = especie;
            }
        } );

        $("#table_especie thead").remove();
        $("#table_especie tfoot").remove();
    }
});

var populateEspecieShowName = function(data) {
    $('#animal_especie_name').text(data[0].name);
};


var populateEspecieTable = function(data) {
    var animais = [];

    $.each(data, function(id_animal, animal){
        animais.push([
            animal.id_animal,
            animal.nome_animal + ': ' + '<br>' + animal.notas_animal,
            animal.foto_animal
        ]);
    });

    $('#table_especie').dataTable().fnClearTable();
    $('#table_especie').dataTable().fnAddData(animais);
    $('#table_especie').dataTable().fnDraw();
};

$('#table_especie tbody').on( 'click', 'tr', function () {
    var animalId = $('#table_especie').DataTable().row(this).data();

    if (animalId !== undefined)
        $.route('animal/' + animalId[0]);
});

$('#table_especie_search').keyup(function(){
    $('#table_especie').DataTable().search($(this).val(), false, true).draw() ;
});

基本上,它使用数据库中的数据来构建表!而且我得到了错误(DataTables警告:表id = table_especie-请求的未知参数'0'为第0行,第0列.有关此错误的更多信息,请参见 http://datatables.net/tn/4 ).该错误使它听起来像是"especie"有问题.我应该怎么做才能使错误消失?它仍然会建立表,但是我之前收到此错误.谢谢!!!

Basically, it builds the table using data from a database! And I get the error (DataTables warning: table id=table_especie - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4) every time I go from table "especies" to table "especie". The error makes it sound like it's something wrong with "especie". What should I change to make the error go away? It still builds the table, but I get this error before. Thanks!!!

推荐答案

解决方案:

"columnDefs": [{
    "defaultContent": "-",
    "targets": "_all"
}],

这篇关于DataTables警告:表ID = table_especie-请求的未知参数'0',用于第0行,第0列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 21:33