我是新來處理dataTable的。我試圖將行轉換成href
使用下面的代碼:dataTable row into hyperlink error
"fnRowCallback": function(row, data) {
$('tr', row).html('<a href="userDet/' + data[3] + '"><td>' +data[0]+ '</td><td>' +data[1]+ '</td><td>' +data[2]+ '</td></a>');
return row;
},
這是不工作,但在轉換href
到單個列。它工作正常。
"fnRowCallback": function(row, data) {
$('td:eq(1)', row).html('<a href="userDet/' + data[3] + '"><td>' +data[0]+ '</td></a>');
return row;
},
我做錯了什麼?
編輯
我html
是:
<table id="myTable" class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Door No</th>
<th>Address</th>
<th style="display: none;">Account ID</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
我Jquery
是:
var oTable = jQuery('#myTable').dataTable({
processing: true,
serverSide: true,
"bDestroy": true,
"pageLength": 6,
"ajax": '/userDetails?query='+query+'',
"type":'get',
"fnRowCallback": function(row, data) {
$('td:eq(1)', row).on('click',function(){
window.location = 'userDet/' + data[3] ;
});
},
"columnDefs": [
{
"targets": [ 3 ],
"visible": false,
"searchable": true
}
]
});
您需要按照表HTML結構..表,TBODY,TR,TD ....如果這個結構斷裂,然後你的CSS將打破和數據表功能可能會打破.. –
謝謝..但我直接導入到'tbody'。數據表沒有問題。唯一的問題是將它們轉換爲'ahref' @Reddy – m2j