0
已将早上花在示例页面上,似乎无法找到为什么这不起作用。如何在数据表中插入TD
意图是用ajax(当前是一个示例txt文件)填充表,并向每行添加一列以允许编辑和删除。已经尝试了下面的代码的各种变体(已经演变为丑陋),但可以明白为什么它不起作用。没有任何错误(在萤火虫或任何其他地方),它只是不会添加列作为“应该”执行的代码。
jQuery(document).ready(function($) {
$(function() {
tableActions();
function initTable()
{
var myTable = $('#example').dataTable({
"iDisplayLength": 10,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"bStateSave": false,
"sAjaxSource": 'datatables_example_arrays.txt',
"aLengthMenu": [[10, 15, 25, -1], [10, 15, 25, "All"]],
"bRetrieve": true
});
return myTable;
}
function tableActions()
{
var oTable = initTable();
/* Insert an 'edit' column with image to the table */
var nCloneTh = document.createElement('th');
var nCloneTd = document.createElement('td');
nCloneTd.innerHTML = '<img src="title_edit.png">';
nCloneTd.className = "center";
$('#example thead tr').each(function() {
oTable.insertBefore(nCloneTh, this.childNodes[0]);
});
$('#example tbody tr').each(function() {
oTable.insertBefore( nCloneTd.cloneNode(true), this.childNodes[0]);
});
}
});
});
根据他们的榜样,是不是需要为每个克隆:http://datatables.net/release-datatables/examples/api/row_details.html – GDP 2012-07-05 19:22:50
@GDP:你说得对,我错过了那里的'cloneNode'电话,很抱歉。 – BLSully 2012-07-05 19:42:09