【问题标题】:DataTables warning: Requested unknown parameter(6) for row (0)数据表警告:为行 (0) 请求未知参数 (6)
【发布时间】:2015-10-09 13:49:33
【问题描述】:

我查看了一些关于此错误的 SO 问题,但没有一个答案能解决我的问题。

HTML

<div id="assign_time_invoice_dialog" title="Select Time" class='assign_time_invoice dialog' style="display:none">
    <table id="time_dt" class="display dt_selectable" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th>Description</th>
                <th>Rate</th>
                <th>Date</th>
                <th>Length</th>
                <th>WIP</th>
                <th>Job</th>
            </tr>
        </thead>
    </table>
</div>

jQuery

$( "#assign_time_invoice_dialog" ).dialog({
      resizable: false,
      height:600,
      width:800,
      modal: true,
      open: function( event, ui ) {
            var data = {client_id:invoice_client_id};
            if (!dataTableCust) {
                dataTableCust = $('#time_dt').DataTable( {
                    'ajax': {
                        'url': 'ajax_time_dt.php',
                        'data': data
                    },
                    "columns": [
                        {"data": "timetrack_description"},
                        {"data": "timetrack_user_rate"},
                        {"data": "timetrack_start"},
                        {"data": "timetrack_length"},
                        {"data": "wip_description"},
                        {"data": "job_description"}
                    ],
                    "columnDefs": [
                        {
                            "targets": [6],
                            "visible": false,
                            "searchable": false,
                        }
                    ],
                    "iDisplayLength": 100,
                    "scrollX": true,
                    "scrollY":        "410px",
                    "scrollCollapse": true,
                    "pagingType": "simple",
                    "oLanguage": {
                      "sSearch": "Search for time:"
                    },
                } );
            }
      },
      buttons : button_options
    });

JSON 响应

{  
   "data":[  
      {  
         "DT_RowId":"1",
         "timetrack_description":"Wednesday timetrack",
         "timetrack_user_rate":"100.00",
         "timetrack_start":"24\/06\/2015",
         "timetrack_length":"10:42",
         "wip_description":"Accounts",
         "job_description":"fifth test job"
      },
      {  
         "DT_RowId":"42",
         "timetrack_description":"New one",
         "timetrack_user_rate":"80.00",
         "timetrack_start":"30\/06\/2015",
         "timetrack_length":"01:30",
         "wip_description":"iXBRL",
         "job_description":"None"
      }
   ]
}

使用此代码,我得到标题中发布的错误。在警报上单击“确定”后,DataTable 将按应有的数据填充数据。检查行也会显示分配给每行的正确 ID。那么为什么我会看到错误呢?

如果我将 "targets" 从“6”更改为“5”,我将不再看到错误,但我也不再看到表中的最后一个“工作”列。

有什么想法我在这里做错了吗?

谢谢,

【问题讨论】:

    标签: jquery datatables


    【解决方案1】:

    您通过在 target[6] 和 visible:none 上使用 columndefs 来隐藏第 7 列 (https://datatables.net/reference/option/columnDefs)

    如果将其更改为 5,则会隐藏第 6 列 ({"data": "job_description"})

    另一个问题似乎是您的标题表的列数少于数据本身。

    【讨论】:

    • 不知道我是怎么错过的,它是 columnDefs。谢谢!
    猜你喜欢
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2015-03-16
    • 2013-05-08
    • 2021-10-24
    • 2014-05-07
    • 2014-09-16
    相关资源
    最近更新 更多