我正在使用https://www.gyrocode.com/projects/jquery-datatables-checkboxes/中的“数据表”复选框。 我已按照说明进行操作,但是未返回我选择的数组。 JavaScript代码:
<script>
$(document).ready(function(){
var tableuser = $("#user_table").DataTable({
"ajax": {
"url" : "http://flazengine-new.local/table-data-new",
"dataType": 'json',
"async": true,
"data" : {
"field":["user_f_id","user_f_name","user_f_phone","user_f_email","user_f_status","user_group_f_name"], "searchs":["user_f_name","user_f_phone","user_f_email","user_f_status","user_group_f_name"], "id":"ZFhObGNsOW1YMmxr", "key":"0", "ids":"0", "table":"Wm1WZmRYTmxjZz09", "module":"user", "query":"Q2drSkNRa0pDVk5GVEVWRFZBb0pDUWtKQ1FrSmRYTmxjbDltWDJsa0xBb0pDUWtKQ1FrSmRYTmxjbDltWDI1aGJXVXNDZ2tKQ1FrSkNRbDFjMlZ5WDJaZmNHaHZibVVzQ2drSkNRa0pDUWwxYzJWeVgyWmZaVzFoYVd3c0Nna0pDUWtKQ1FsMWMyVnlYMlpmYzNSaGRIVnpMQW9KQ1FrSkNRa0pkWE5sY2w5bmNtOTFjRjltWDI1aGJXVUtDUWtKQ1FrSlJsSlBUUW9KQ1FrSkNRa0pabVZmZFhObGNnb0pDUWtKQ1FsTVJVWlVJRXBQU1U0S0NRa0pDUWtKQ1dabFgzVnpaWEpmWjNKdmRYQUtDUWtKQ1FrSlQwNEtDUWtKQ1FrSkNXWmxYM1Z6WlhJdWRYTmxjbDl5WDNWelpYSmZaM0p2ZFhCZlpsOXBaQ0E5SUdabFgzVnpaWEpmWjNKdmRYQXVkWE5sY2w5bmNtOTFjRjltWDJsa0Nna0pDUWtKQ1E9PQ}}", "bind":"0", "modal":"1", "edit":"1", "delete":"1", "divider":"0", "action":"0", "modals":"0", "modal_file":"0", },
"type": "POST",
"complete" : function(){
},
"error" : function (xhr, error, thrown){
console.log(xhr);
}
},
"destroy": false,
"language": {
"lengthMenu" : "Menampilkan _MENU_ record per halaman",
"zeroRecords" : "Tabel Kosong",
"info" : "Memunculkan halaman _PAGE_ dari _PAGES_",
"infoEmpty" : "Tidak ada data ditemukan.",
"infoFiltered" : "(ditemukan _MAX_ jumlah records)",
"processing" : "Proses menampilkan data...",
},
"bProcessing": true,
"bServerSide": true,
"searchDelay": null,
"columnDefs": [
{
'targets': 0,
'checkboxes': {
'selectRow': true
}
},
{
widthuser
}
],
"select": {
'style': 'multi'
},
'order': [[1, 'asc']]
});
window.showdata = function(){
var selecteduser = tableuser.columns(0).checkboxes.selected();
var itemselecteduser = [];
$.each(selecteduser, function(index, rowId){
itemselecteduser.push(rowId);
});
console.log(itemselecteduser);
}
});
这是我的数据:
{
"draw":1,
"recordsTotal":3,
"recordsFiltered":3,
"data":
[
[
"TkRjd0lDQWdJQ0FnSUNBZ0lDQWdJQ0FnSUNBZ0lDQWdJQ0FnSUNBZ0lDQWdJQ0Fn",
1,
"Administrator",
"123456",
"admin@aku.com",
"Active",
"Administrator",
"<div class='btn-group'> <div class='btn btn-success btn-sm' onclick='getdatauser(\"470 \")' role='button' data-toggle='modal' title='Ubah' data-target='#addDatauser'><i class='fa fa-edit'><\/i><\/div> <div class='btn btn-danger btn-sm' role='button' data-toggle='tooltip' title='Hapus' id='delete470 '><i class='fa fa-remove'><\/i><\/div> <script> $(document).ready(function(){ $('#user_table tbody').on('click','#delete470 ',function(e){ var href = $(this).attr('href'); swal({ title: 'Delete Data?', type: 'warning', showCancelButton: true, confirmButtonColor: '#DD6B55', confirmButtonText: 'Yes, Delete!', cancelButtonText: 'No, Cancel!', closeOnConfirm: true, closeOnCancel: true }, function (isConfirm){ if (isConfirm){ $.ajax({ type: 'POST', async: false, url: 'http:\/\/flazengine-new.local\/user-delete', data: {table:'Wm1WZmRYTmxjZz09',where:'ZFhObGNsOW1YMmxr',id:'TkRjd0lDQWdJQ0FnSUNBZ0lDQWdJQ0FnSUNBZ0lDQWdJQ0FnSUNBZ0lDQWdJQ0Fn'}, cache: false, dataType: 'json', success: function(res){ if(res['status'] === 'success'){ console.log('Status Nih: '+res['status']); $('#user_table').DataTable().ajax.reload(); }else{ alert(res['message']); } } }); } }); return false; }); }); <\/script> <\/div>"
],
[
"T0dReU1qa3pOMlF0TW1FMk1TMDBNV1ptTFdGa016VXRPVEl6Wm1KallXVm1OalJp",
2,
"COBA LAGI AJAH",
"123456",
"coba@coba.com",
"Active",
"Administrator",
"<div class='btn-group'> <div class='btn btn-success btn-sm' onclick='getdatauser(\"8d22937d-2a61-41ff-ad35-923fbcaef64b\")' role='button' data-toggle='modal' title='Ubah' data-target='#addDatauser'><i class='fa fa-edit'><\/i><\/div> <div class='btn btn-danger btn-sm' role='button' data-toggle='tooltip' title='Hapus' id='delete8d22937d-2a61-41ff-ad35-923fbcaef64b'><i class='fa fa-remove'><\/i><\/div> <script> $(document).ready(function(){ $('#user_table tbody').on('click','#delete8d22937d-2a61-41ff-ad35-923fbcaef64b',function(e){ var href = $(this).attr('href'); swal({ title: 'Delete Data?', type: 'warning', showCancelButton: true, confirmButtonColor: '#DD6B55', confirmButtonText: 'Yes, Delete!', cancelButtonText: 'No, Cancel!', closeOnConfirm: true, closeOnCancel: true }, function (isConfirm){ if (isConfirm){ $.ajax({ type: 'POST', async: false, url: 'http:\/\/flazengine-new.local\/user-delete', data: {table:'Wm1WZmRYTmxjZz09',where:'ZFhObGNsOW1YMmxr',id:'T0dReU1qa3pOMlF0TW1FMk1TMDBNV1ptTFdGa016VXRPVEl6Wm1KallXVm1OalJp'}, cache: false, dataType: 'json', success: function(res){ if(res['status'] === 'success'){ console.log('Status Nih: '+res['status']); $('#user_table').DataTable().ajax.reload(); }else{ alert(res['message']); } } }); } }); return false; }); }); <\/script> <\/div>"
],
[
"TURRMU9UQXlZalV0TmpZeU55MDBPVE0wTFRnNVpqZ3RNVFF3TURGbFltUXlNV1Zt",
3,
"APA AJAH",
"123456",
"apaajah@apaajah.com",
"Active",
"Administrator",
"<div class='btn-group'> <div class='btn btn-success btn-sm' onclick='getdatauser(\"045902b5-6627-4934-89f8-14001ebd21ef\")' role='button' data-toggle='modal' title='Ubah' data-target='#addDatauser'><i class='fa fa-edit'><\/i><\/div> <div class='btn btn-danger btn-sm' role='button' data-toggle='tooltip' title='Hapus' id='delete045902b5-6627-4934-89f8-14001ebd21ef'><i class='fa fa-remove'><\/i><\/div> <script> $(document).ready(function(){ $('#user_table tbody').on('click','#delete045902b5-6627-4934-89f8-14001ebd21ef',function(e){ var href = $(this).attr('href'); swal({ title: 'Delete Data?', type: 'warning', showCancelButton: true, confirmButtonColor: '#DD6B55', confirmButtonText: 'Yes, Delete!', cancelButtonText: 'No, Cancel!', closeOnConfirm: true, closeOnCancel: true }, function (isConfirm){ if (isConfirm){ $.ajax({ type: 'POST', async: false, url: 'http:\/\/flazengine-new.local\/user-delete', data: {table:'Wm1WZmRYTmxjZz09',where:'ZFhObGNsOW1YMmxr',id:'TURRMU9UQXlZalV0TmpZeU55MDBPVE0wTFRnNVpqZ3RNVFF3TURGbFltUXlNV1Zt'}, cache: false, dataType: 'json', success: function(res){ if(res['status'] === 'success'){ console.log('Status Nih: '+res['status']); $('#user_table').DataTable().ajax.reload(); }else{ alert(res['message']); } } }); } }); return false; }); }); <\/script> <\/div>"
]
]
}
数据表图片: Datatable Checkbox
Console.log的结果: Result of Console.log
我需要返回数据表的选定行。请帮忙吗?
答案 0 :(得分:0)
在您的上下文中,您需要使用column(0).checkboxes.selected()
而不是columns(0).checkboxes.selected()
。 API方法columns()
的返回值不同于column()
。