我已经看了几个关于这个错误的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',那么我就不会再看到错误,但我也不再看到表格中的最后一个'作业'列。
我在这里做错了什么想法?
谢谢,
答案 0 :(得分:1)
您使用target [6]上的columndef和visible:none来隐藏第7列 (https://datatables.net/reference/option/columnDefs)
如果您将其更改为5,则会隐藏第6列({&#34;数据&#34;:&#34; job_description&#34;})
另一个问题似乎是您的标头表的列数少于数据本身。