【问题标题】:how to solve cannot read property 'mDATA' in Datatables如何解决无法读取数据表中的属性“mDATA”
【发布时间】:2019-12-12 11:45:39
【问题描述】:

我已经用 django 配置了数据表,它在最多有 6 列时工作得很好。当我尝试再添加一列时,出现错误“未捕获的类型错误:无法读取未定义的属性‘mData’” 当我在 chrome 中检查时,得到错误显示的行 (c.mData ===): if(c.mData=== a){var d=w(b,"sort")||w(b,"order"),e=w(b,"filter")||w(b,"search");if(d! ==null||e!==null){c.mData={_:a+".display",sort:d!==null?a+".@data-"+d:k,type:d!= =null?a+".@data-"+d:k,filter:e!==null?a+".@data-"+e:k};ja(p,a)}}})}var T= p.oFeatures,e=function(){if(g.aaSorting===k){var a=p.aaSorting;j=0;for(i=a.length;j

我尝试给静态数据检查是否因为动态渲染,仍然出现同样的问题。

这是我的html页面,

table.html

<div class="row mb-4">
            <div class="col-12 mb-4">
            <div class="card">
                <div class="card-body">
                    <table class="data-table data-table-feature" id="dtable">
                        <thead>
                            <tr>
                                <th>Code</th>
                                <th>Description</th>
                                <th>Sort key</th>
                                <th>Is delete</th>
                                <th>Prefix</th>
                                <th>Edit</th>
                                <th>TEST</th>
                            </tr>
                        </thead>
                        <tbody>
                           {% for i in areas %}
                            <tr>

                                <td>{{ i.code }}</td>
                                <td>{{ i.description }}</td>
                                <td>{{ i.sort_key }}</td>
                                <td>{{ i.is_deleted }}</td>
                                <td>{{ i.prefix }}</td>
                                <td><a href="{% url 'edit-area-master' i.id %}">edit</a></td>
                                <td>TEST</td>
                            </tr>
                            {% endfor %} 
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

我交叉检查了所有表格标签,请指出我哪里出错了。

【问题讨论】:

    标签: django datatables


    【解决方案1】:

    我找到了解决方案,现在我可以添加任何一列。

    test.html

    <table id="example" class="display" style="width:100%">
                   <thead>
                     <tr>
                       <th></th>
                       <th>Name</th>
                       <th>Position</th>
                       <th>Edit</th>
                    </tr>
                  </thead>
                  <tbody>
                    {% for i in branches %}
                    <tr>
                      <td></td>
                      <td>{{ i.code }}</td>
                      <td>{{ i.description }}</td>
                      <td><a href="{% url 'edit-branch-master' i.id %}"
                         class="glyph-icon simple-icon-note"></a></td>
                    </tr>
                  {% endfor %}
                 </tbody>
    </table>
    
    
    <script>
    $(document).ready(function () {
        var t = $('#example').DataTable({
            "columnDefs": [{
                "searchable": false,
                "orderable": false,
                "targets": 0
            }],
            "order": [[1, 'asc']]
        });
    
        t.on('order.dt search.dt', function () {
            t.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
                cell.innerHTML = i + 1;
            });
        }).draw();
    });
    </script>
    

    【讨论】:

      猜你喜欢
      • 2021-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      相关资源
      最近更新 更多