【发布时间】:2015-04-22 18:37:07
【问题描述】:
我正在使用 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>
【问题讨论】:
标签: javascript jquery json datatables jquery-datatables