私はあなたの問題を考え出したし、同様にいくつかの変更を行いました。 有効なhtmlではないので、入力したすべてのdivを削除しました。 フォーマット関数では、d.msgInfoが存在しないようにデータ列を決して定義しません。行のデータは配列内にあるので、私の変更されたコードではそのd [15]です。
ただ楽しいため、個々の行を展開するためのボタンの列を追加しました。 また、上部のリンクを削除して、テーブルの下部にあるボタンに置き換えました。
http://live.datatables.net/bovonodi/1/edit
var table = $('#example').DataTable(
{ "columnDefs" : [ { "targets" : -1, "visible" : false, "name" : 'msg_info'} ],
"iDisplayLength" : 15,
dom:'tBp',
"aLengthMenu" : [ [15, 25, 50, 100, -1 ], [ 15, 25, 50, 100, "All" ] ],
"order" : [ [ 2, "desc" ] ],
columns:[ {
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},null, null, null, null, null, null,
null, null, null, null, null, null,
null, null, null],
buttons:[{text:'Show Info', action:function(e, dt, node, config){
if(node[0].innerText == "Show Info"){
node[0].innerText = "Hide Info";
hideShowExtraInfo(true);
}
else {
node[0].innerText = "Show Info";
hideShowExtraInfo(false);
}
}}]
});
$('#example tbody').on('click', 'td.details-control', function() {
var tr = $(this).closest('tr');
var row = table.row(tr);
var td = $(this);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
td.removeClass('shown');
}
else {
// Open this row
row.child(format(row.data())).show();
td.addClass('shown');
}
});
});
function hideShowExtraInfo(doShow) {
var table = $('#example').DataTable();
table.rows().every(function() {
console.log("Temp");
var tr = $(this.node());
var td = tr.children(".details-control");
if (!doShow) {
// This row is already open - close it
this.child.hide();
td.removeClass('shown');
} else {
// Open this row
this.child(format(this.data())).show();
td.addClass('shown');
}
});
}
function format(d) {
// `d` is the original data object for the row
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'
+ '<tr><td>Message Info:</td><td>'
+ d[15]
+ '</td></tr></table>';
}
あなたが例を以下している場合、私はそれへのリンクを参照してくださいしたいと思います。 trの間にdivを挿入しようとしています。それは不適切な形式のHTMLです。 – Bindrid