【发布时间】:2014-01-16 20:05:40
【问题描述】:
我正在尝试用数据填充表格的列标题及其正文,但是如果它无法进行 ajax 调用。
<table id="datatable1" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
<thead>
</thead>
<tbody>
</tbody>
</table>
我让头部和身体都空着。 但是添加一些随机标题。
<thead>
<tr>
<th>Random column title</th>
</tr>
</thead>
修复它。虽然我的意思是同时从 JSON 字符串中添加列名和数据并将其添加到表中,但它不会让我这样做:
如果事先建立了正确的aoColumns 和mData,我也可以从数据库中加载内容。
var oTable; //datatable reference
var start = 0; //first row's id to load
var qty = 100; //number of rows to load
var DESC = "false"; //load last row first and go down?
var type = "something";
var ajaxURL = GLOBAL_ROUTE + "api/application/datatable/fillTable/" + type + "/" + start + "/" + qty + "/" + DESC;
oTable = $('#datatable1').dataTable({
"sPaginationType" : "full_numbers",
"sDom" : '<"top"<"length"l><"search"f><"position">>rt<"bottom"<"info"i><"pages"p>>',
"bProcessing" : false,
"bServerSide" : false,
"sAjaxSource" : ajaxURL,
"bDeferRender" : true,
/*"aoColumns" : [ {
"mData" : "a"
}, {
"mData" : "b"
}, {
"mData" : "c"
}, {
"mData" : "d"
} ]*/
});
alert("asasd"); //this alert is not even reached if no header/body/aoColumns are set.
在不事先使用列名进行 ajax 调用的情况下,有什么方法可以解决这个问题?
【问题讨论】:
标签: java jquery ajax jsp datatables