0
我想在我的數據表中添加2個額外的列(編輯和刪除)。 我的數據表中的每一行都包含一個隱藏列,它是記錄ID,所以當用戶點擊編輯或刪除我想獲得選定的行ID。Jquery Datatable編輯/刪除圖標
$(document).ready(function() {
var mytable = $('#userTable').DataTable({
"fixedHeader": {
"header": true,
"footer": true
},
"lengthMenu": [[25, 50, 100, 200, -1], [25, 50, 100, 200, "All"]],
"ajax": {
"url": "/Users/Prov",
"type": "Get",
"data": { "id": "@userId", "cityId": "@cityId" },
"datatype": "json"
},
"columnDefs": [
{
"targets": -1,
"data": null,
"defaultContent": "<button>Delete!</button>"
}
],
"columns": [
{ "data": "Id", "visible": false, "searchable": false },
{ "data": "Name" },
{ "data": "City" },
{ "data': "Code" },
{ "data': "Title" },
]
});
$('#userTable tbody').on('click', 'button', function() {
var rowData = mytable.row($(this).parents('tr')).data();
alert(rowData[1] + "'s City is: " + rowData[2]);
});
});
謝謝Ehsan Sajjad – Maro