jquery - 如何将每行的删除按钮添加到 Jquery DataTable
问题描述
我正在使用 Jquery DataTable,我想对 DataTable 的每一行使用编辑和删除功能,并且我已经完成了单击 DataTable Row 的编辑部分。现在我正在寻找删除功能,但我无法实现相同的功能。
我试过这样:
数据表绑定代码:
function LoadTableData() {
var params = {
UserName: $('#txtUserName').val(), UserID: $('#txtUserID').val(),
Status: $('input[name="Status"]:checked').val()
};
$.ajax({
url: 'UserService.asmx/Get_Data_MobileUser',
method: 'post',
data: JSON.stringify(params),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
$('#example').dataTable({
destroy: true,
data: data /*JSON.parse(data)*/,
columns: [
{
render: function (data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1;
}
},
{ 'data': 'Status', class: 'editable text' },
{ 'data': 'USER_LOGIN', class: 'editable text' },
{ 'data': 'USER_NAME', class: 'editable text' },
],
"columnDefs": [
{
"render": function (data, type, row) {
return '<button type="button">Delete</button>';
//return data + ' (' + row[3] + ')';
},
"targets": 0
},
{ "visible": false, "targets": [3] }
],
dom: 'Bfrtip',
select: true,
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
"searching": true,
"paging": true,
"info": true,
"language": {
"emptyTable": "No data available"
},
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
$("td:first", nRow).html(iDisplayIndex + 1);
return nRow;
},
})
//function createButton(buttonType, rowID) {
// var buttonText = buttonType == "edit" ? "Edit" : "Delete";
// //return '<button class="' + buttonType + '" type="button">' + buttonText + '</button>';
// return "<a href='#my_modal' data-toggle='modal' class='open-AddBookDialog' data-book-id='my_id_value'><img src='Images/delete.png' height='20' width='20'></a>"
//}
},
error: function (err) { // Added this event to capture the failed requests.
console.log(err.responseText);
}
});
};
表结构
<table id="example" class="display" style="width: 100%">
<thead>
<tr>
<th>S.No</th>
<th>Status</th>
<th>User Login</th>
<th>User Name</th>
<th>Delete</th>
</tr>
</thead>
</table>
但在控制台窗口我收到错误:
未捕获的 TypeError:$.fn.dataTable.Editor 不是构造函数
我是否为此错过了任何 CDN?
我怎么了?
解决方案
推荐阅读
- c# - c#中的休眠映射
- r - geom_line 中各个破折号的交替颜色
- wordpress - 将愿望清单添加到“我的帐户”页面 wooCommerce - 问题
- python - 对于 Python 套接字,有没有办法设置使用的本地接口?
- security - 使用外部身份验证提供程序将用户存储在我的数据库中
- c# - WCF 下 SOAP Web 服务的同时客户端证书和用户名身份验证
- eclipse - 如何在具有不同拱门的远程机器上分析特定线程?
- javascript - 变量被分配了一个值但从未使用过,除非它实际被使用
- html - React - 无法让 CDN 字体在 Safari 浏览器上工作
- c# - 将 RichTextBox 绑定到 FlowDocumentReader 内部的内容时,它变为 ReadOnly