【问题标题】:JQquery data table warning when table is empty表为空时的JQuery数据表警告
【发布时间】:2014-08-29 04:25:28
【问题描述】:

我有这个警告

DataTables 警告(表 id = 'datatabledetail'):意外数字 TD 元素。预期为 3,得到 0。DataTables 不支持 表体中的rowspan / colspan,并且必须有一个单元格 每行/列组合。

当我的桌子是空的,

我该怎么办??

这是我的数据表代码

var oTableDetail = $('#datatabledetail').dataTable({
        "bSort": false,
        "bAutoWidth": false,
        "bProcessing": false,
        "bFilter": false,
        "bPaginate": false,
        "aoColumns": [
                        { "mDataProp": "Id", "bVisible": true },
                        { "mDataProp": "CodeValue", "bVisible": true },
                        { "mDataProp": "NameValue", "bVisible": true }
        ]//
        ,
        "aoColumnDefs": [
                            {
                                "fnRender": function (o) {
                                    return "<center>  <input type='button' id='" + o.aData['Id'] + "' class='cremove mws-button blue' value='Remove'></center>";
                                },
                                "aTargets": [0]
                            }
        ]
    });

这是我的 html 代码

<table cellpadding="0" cellspacing="0" border="0" class="mws-table" id="datatabledetail"
                               width="100%">
                            <thead>
                                <tr>
                                    <th style="text-align: center; width: 5%;">
                                        Action
                                    </th>
                                    <th style="text-align: center; width: 40%;">
                                        Food Name
                                    </th>
                                    <th style="text-align: center; width: 10%;">
                                        Food Code
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>

                                </tr>
                            </tbody>
                        </table>

【问题讨论】:

  • 显示数据表代码...
  • 你可以设置一个条件,如果你得到一些数据而不是应用数据表,否则不应用数据表只是显示空表。

标签: javascript jquery asp.net datatable


【解决方案1】:

在 DataTable 库中,您不能在 html 标记中使用任何属性 rowspan 或 colspan,并确保表格标题和表格正文之间的列数匹配,例如:

<table id="xyz">
   <thead>
     <tr>
       <th>Heading 1</th>
       <th>Heading 2</th>
       <th>Heading 3</th>
       <th>Heading 4</th>
     <tr>
   </thead>
   <tbody>
     <tr>
       <td>Content</td>
       <td>Content</td>
       <td>Content</td>
       <td>Content</td>
     <tr>
     <tr>
       <td>Content</td>
       <td>Content</td>
       <td>Content</td>
       <td>Content</td>
     <tr>
     <tr>
       <td>Content</td>
       <td>Content</td>
       <td>Content</td>
       <td>Content</td>
     <tr>
     <tr>
       <td>Content</td>
       <td>Content</td>
       <td>Content</td>
       <td>Content</td>
     <tr>
   </tbody>
</table>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 2021-06-28
    相关资源
    最近更新 更多