我一直在尝试通过使用来自ajax请求的数据来填充表。我一直关注this tutorial作为起点。
我在查询时创建了一个PHP Web服务:
table_ws.php?id=2
以下列格式返回数据:
{"status":200,"status_message":"Yahoo!","data":[{"sent_date":"2012-01-01","serial_number":"342312","text":"Great service","looked_into":"0"},{"sent_date":"2012-02-16","serial_number":"2343662","text":"Happy with the product","looked_into":"0"},{"sent_date":"2012-03-04","serial_number":"342356","text":"Experience could have been better","looked_into":"0"}]}
我用HTML创建了表格,如下所示:
<table id="tbl_details" class="tbl">
<thead>
<tr>
<th>Sent Date</th>
<th>Number</th>
<th>Text</th>
<th>Resolved?</th>
</tr>
</thead>
</table>
我的javascript的相关部分如下(为了清楚起见,我排除了与问题无关的代码):
...
...
...
.on("click", function(d) {
table.ajax="table_ws.php?id=" + d.id
table.columns=[
{"data": "sent_date"},
{"data": "serial_number"},
{"data": "text"},
{"data": "looked_into"}
];
});
...
...
...
$(document).ready( function () {
table=$('#tbl_details').DataTable();
table.processing=true;
table.serverSide=true;
});
虽然该表在页面上显示为预期的,但它没有填充&#34; onclick&#34;按钮。
StackOverflow上的The answer to this question表示每次放入新数据时都需要销毁和重新创建表。但函数fnDestroy()似乎不存在。
如何解决这个问题?