javascript - 在 jQuery DataTables 中的所有行前面放置一个按钮

标签 javascript jquery json datatables

我正在使用 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/

相关文章:

javascript - Mongoose.Create 未发送分配的值

javascript - Mysql 根据另一个下拉选项填充下拉列表

javascript - 通过AngularJS将json格式转换为另一种json格式

javascript - 如何使用 css 或 jq 在 laravel 中创建图像 slider

javascript - Bootstrap 响应式布局中的 Ytplayer

javascript - AJAX、Django 和 HTML 选择?

javascript - 使用 javascript/Jquery 在 MouseOver 之后删除元素的颜色

javascript - 读取 JSON 文件并以图形 TreeView 表示它

android - 在 android 中使用 Jackson Parser 解析 Json?

json - 无法使用带有预取功能的 Bloodhound 使 Twitter typeahead 0.10 正常工作