TypeError C是未定义的数据表 [英] TypeError C is undefined datatables

查看:78
本文介绍了TypeError C是未定义的数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将通过ajax获得的一些数据呈现到数据表中,但似乎缺少了某些内容,因为它显示错误:TypeError:c未定义。

I'm trying to render some data that i get with ajax into a datatable, but it seems I'm missing something, because it displays the error: TypeError: c is undefined.

我已经阅读了这篇文章,数据表TypeError:c未定义,但是给出的任何解决方案都无法解决我的问题。任何人都有可以帮助我的想法吗?谢谢。

I've read this post, Datatables TypeError: c is undefined, but any solution given hasn't solved my problem. Anyone have an idea that could help me? Thank you.

html代码:

<table id="itinerariDetailTable" class="table table-sm table-striped table-bordered" style="font-size: x-small;">
                        <thead class="thead-inverse">
                            <tr>
                                <th>Id</th>
                                <th>Codi</th>
                                <th>Descripció</th>
                                <th>Temporada</th>
                                <th>Districte</th>
                                <th>Barri</th>
                                <th>C. Treball</th>
                                <th>G. Servei</th>
                                <th>T. Servei</th>
                                <th>Máquina</th>
                                <th>Corretorn</th>
                                <th>Torn</th>
                                <th>Tipus Día</th>
                                <th>Equips</th>
                                <!-- <th>Jornades</th>
                                <th>Cost unitari</th>
                                <th>T. Itinerari</th>
                                <th>Escenario</th> -->                              
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <th>Id</th>
                                <th>Codi</th>
                                <th>Descripció</th>
                                <th>Temporada</th>
                                <th>Districte</th>
                                <th>Barri</th>
                                <th>C. Treball</th>
                                <th>G. Servei</th>
                                <th>T. Servei</th>
                                <th>Máquina</th>
                                <th>Corretorn</th>
                                <th>Torn</th>
                                <th>Tipus Día</th>
                                <th>Equips</th>
                                <!-- <th>Jornades</th>
                                <th>Cost unitari</th>
                                <th>T. Itinerari</th>
                                <th>Escenario</th> -->                              
                            </tr>
                        </tfoot>
                    </table>

js代码:

$('#itinerariDetailTable').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax":{
            "url":'/escenaris/selectById',
            "type":'GET',
            "data": function(d){
                d.idEscenari = $('#idEscenari').val();                  
            }
        },
        "order": [[ 0, "asc" ]],
        "columns": [
            { "data": "idItinerari" },
            { "data": "codiItinerari" },
            { "data": "descripcio" },
            { "data": "temporada.codiTemporada" },
            { "data": "districte" },
            { "data": "barri" },
            { "data": "centreTreball" },
            { "data": "grupServei" },
            { "data": "tractamentRecursos" },
            { "data": "maquinaCombustible" },
            { "data": "corretorn" },
            { "data": "torn" },
            { "data": "tipusDia" },
            { "data": "nombreEquips" }
            /*{ "data": "frequencia" },
            {"data": "resultatItinerari.costUnitari", "defaultContent": "0" },
            { "data": "tipusItinerari.codiTipusItinerari" }/*,                          
            { "data": "escenari.idEscenari" }           */  
        ]
    });


推荐答案

问了很长时间,但是我已经在多个线程中看到了,所以我将分享我的答案以供将来参考。

It's a long time since this question has been asked, but I've seen it in several threads, so I'm gonna share my answer for future reference.

这种类型的错误通常与(如果不是特别的话)相关HTML table 元素的结构。

This type of error is most often (if not particularly) related to the structure of the HTML table element.

根据DataTables手册:'使DataTables能够增强HTML表格,该表格必须是有效的,格式正确的HTML,带有标题( thead )和单个正文( tbody )。也可以使用可选的页脚( tfoot )。'

According to to the DataTables manual: 'For DataTables to be able to enhance an HTML table, the table must be valid, well formatted HTML, with a header (thead) and a single body (tbody). An optional footer (tfoot) can also be used.'

上面的代码缺少 tbody 标记,这似乎是问题所在。

The above code is missing the tbody tag, which seems to be the issue.

这篇关于TypeError C是未定义的数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆