 |
สอบถามการส่งค่าผ่าน Ajax ก่อน เเล้วค่อย Export Excel ต้องส่งค่าไปยังไงและรับยังไงค่ะ คือต้องการคลิกปุ่ม Export Excel หลังจากทำการค้นหาจากช่อง |
|
 |
|
|
 |
 |
|
ผมใช้ตัว ถ้าข้อมูลเยอะก็ต้อง filterข้อมูลจาก ค้นหา ก่อนนำมาใส่ใน DataTables
- DataTables ร่วมกับ print_datatables จาก https://datatables.net/extensions/buttons/examples/initialisation/export.html
- https://datatables.net/extensions/buttons/examples/print/simple.html
ตัวอย่างประมาณนี้
Code (JavaScript)
<script>
$(document).ready(function() {
var currentYear = (new Date).getFullYear();
//alert(currentYear);
$('#dataTables1').dataTable({
responsive: true,
"order": [[ 0, "desc" ]],
"lengthMenu": [[-1, 10, 25, 50, 100], ["All", 10, 25, 50, 100]],
"processing": true,
"serverSide": true,
"ajax": "../server_side/scripts/server_processing.php"
//"sAjaxSource":"response.php",
//"dom": 'lBfrtip',
"buttons": [
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
],
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
}
});
});
</script>
ส่วนที่เพิ่มมาจาก DataTables ธรรมดาคือ ปุ่มสำหรับ Print หรือ Export CSV
Code (JavaScript)
"buttons": [
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
],
|
ประวัติการแก้ไข 2017-08-04 19:01:08
 |
 |
 |
 |
Date :
2017-08-04 18:53:25 |
By :
ccjpn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มี code อะไรเลย แล้วจะแก้ยังไง เหอะๆ
|
 |
 |
 |
 |
Date :
2017-08-07 08:40:23 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ให้มองปุ่มexport เป็นปุ่มลิงค์ที่ต้องส่งขัอมูลที่จำเป็นในการ select database เพื่อใหได้ขัอมูลในการทำ excel ทั้งหมด
|
 |
 |
 |
 |
Date :
2017-08-07 09:31:37 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$('#table_print').DataTable({
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$( ".print" ).click(function() {
var rel = $(this).attr('rel');
var s = $("input[name='start"+rel+"']").val();
var e = $("input[name='end"+rel+"']").val();
var r = $("input[name='round"+rel+"']").val();
var n = $("input[name='nameid"+rel+"']").val();
console.log("rel:"+rel+"/start:"+s+"/end:"+e+"/round:"+r+"/"+n+"");
if ( $.trim( s ) === '' || $.trim( e ) === '' || $.trim( r ) === '' || $.trim( n ) === '' ){
alert('Error');
return false;
}else{
var url = "<?php echo site_url('code/export'); ?>/"+s+"/"+e+"/"+r+"/"+n+"";
window.open(url, '_blank');
}
});
}
});
|
 |
 |
 |
 |
Date :
2017-08-07 14:43:33 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|