I hava 2 DataTables: First is called "Transaction" and second is called "Detail transaction". The Idea is very simple. I want to pass variable when I click "detail button" on Transaction so I can get the detail accordingly. The "detail button" contains "transaction_id" that is used to initiate "Detail transaction".
My Javascript
//DataTables that shows "Transaction" list
var table = $('.data-table').DataTable({
processing: true,
serverSide: false,
order: [[ 0, "desc" ]],
ajax: "",
columns: [
{data: 'id_transaksi', name: 'id_transaksi', 'visible': true},
{data: 'tgl_berangkat', name: 'tgl_berangkat'},
{data: 'tgl_pulang', name: 'tgl_pulang'},
{data: 'keperluan', name: 'keperluan'},
{data: 'jml_personil', name: 'jml_personil'},
{data: 'lokasi', name: 'lokasi'},
{data: 'action', name: 'action', orderable: false, searchable: false},
]
});
//Button event that should trigger another DataTables to show data
$('body').on('click', '.detailPersonil', function(){
//I need this ID to be passed to Datatable bellow
var id_transaksi = $(this).data('id');
console.log(id_transaksi);
});
//DataTable that shows detail transaction
$('.detail_transaksi').DataTable({
processing: true,
serverSide: false,
order: [[ 0, "desc" ]],
ajax: 'sppd/'+2+'/detail_transaksi', //I want to POST ID here everytime I click the "detail button"
columns: [
{data: 'id', name: 'id', 'visible': true},
{data: 'id_transaksi', name: 'id_transaksi'},
{data: 'nama_lengkap', name: 'nama_lengkap'},
{data: 'nip', name: 'nip'},
{data: 'pangkat', name: 'pangkat'},
{data: 'ref_bag_id', name: 'ref_bag_id'},
{data: 'action', name: 'action', orderable: false, searchable: false},
]
});
This is my Controller
public function show_data(){
$table = DB::table('sppd_tb_transaksi')
->select('sppd_tb_transaksi.id AS id_transaksi',
'sppd_tb_transaksi.lokasi AS lokasi','sppd_tb_transaksi.tgl_berangkat',
'sppd_tb_transaksi.tgl_pulang', 'sppd_tb_transaksi.jml_personil',
'sppd_tb_transaksi.keperluan')
->get();
return Datatables::of($table)
->addColumn('action', function($row){
$btn = '<a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id_transaksi.'" data-original-title="Edit" class="btn btn-primary btn-sm editKegiatan" style="font-size:11px;"><i class="fa fa-edit"></i> Edit </a> <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id_transaksi.'"class="btn btn-info btn-sm detailPersonil" style="font-size:11px;"><i class="fa-info-circle"></i>Detail</a>';
$btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id_transaksi.'" class="btn btn-warning btn-sm printKegiatan" style="font-size:11px;"><i class="fa fa-print"></i> Print</a> <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id_transaksi.'" data-original-title="Delete" class="btn btn-danger btn-sm deleteKegiatan" style="font-size:11px;"><i class="fa fa-trash"></i> Delete</a>';
return $btn;
})->make(true);
}
Any Ideas? Please help me guys
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire