我正在使用 jQuery 数据表。它正在使用数据库中的 JSON 数据进行填充。我不知道如何在每条记录前面显示按钮或链接。我想要做到这一点,以便当用户单击该按钮时,该特定记录就会添加到数据库中,因此按钮或链接应该包含一个 ID。请帮助解决我的问题。 下面是我正在使用的代码:
var oTable = $('#jsontable').dataTable();
$.ajax({
url: 'process.php?method=fetchdata',
dataType: 'json',
success: function(s) {
console.log(s);
oTable.fnClearTable();
for (var i = 0; i < s.length; i++) {
oTable.fnAddData([
s[i][3],
s[i][4],
s[i][0], // this contains id
]);
}
},
error: function(e) {
console.log(e.responseText);
}
});
<table id="jsontable" class="display table table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Class Number</th>
<th>Subject</th>
<th>ADD</th>
</tr>
</thead>
</table>
最佳答案
希望这对您有帮助
oTable = $('#jsontable').dataTable({
"fnRowCallback": function (nRow, aaData, iDisplayIndex) {
//nRow Row Object
//aaData Param
//iDisplayIndex Row Index
$('td:eq(0)', nRow).html("<input type='button'>Button</input>");
return nRow;
}
});
关于javascript - 在 jQuery DataTables 中的所有行前面放置一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29806169/