< script > $('.input-daterange').datepicker({ todayBtn: 'linked', format: "dd-mm-yyyy", autoclose: true }); $('#example thead tr').clone(true).addClass('search').appendTo('#example thead'); $('#example thead tr:eq(1) th').text(""); fetch_data('no'); function fetch_data(is_date_search, start_date = '', end_date = '') { var table = $('#example').DataTable({ "processing": true, "serverSide": true, "order": [], "lengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ], "ajax": { url: "cashentry_serverdata.php", type: "POST", data: { is_date_search: is_date_search, start_date: start_date, end_date: end_date }, }, //to hide datatable column "columnDefs": [ { 'visible': false, 'targets': [] } //to hide table column ], "order": [ [0, "desc"] ], 'destroy': true, 'orderCellsTop': true, // to search individual column value initComplete: function() { var api = this.api(); // For each column api .columns([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) .eq(0) .each(function(i) { // Set the header cell to contain the input element var cell = $('.search th').eq( $(api.column(i).header()).index() ); var title = $('#example thead tr:eq(1) th').text(); $(cell).html(''); // On every keypress in this input $('input', this).on('keyup change', function(e) { if (e.keyCode == 13) { e.preventDefault(); if (table.search() !== this.value) { table .search(this.value) .draw(); } } }); }); }, dom: 'l<"toolbar">frtip', "footerCallback": function(row, data, start, end, display) { var api = this.api(), data; // Remove the formatting to get integer data for summation var intVal = function(i) { return typeof i === 'string' ? i.replace(/[\$,]/g, '') * 1 : typeof i === 'number' ? i : 0; }; //to hide datatable column table.column(13).visible(false); table.column(14).visible(false); table.column(15).visible(false); // Update div.toolbar with comma seperated values var numFormat = $.fn.dataTable.render.number('\,', '.', 2, ).display; // Total over all pages along with updating div.toolbar with comma separated values as per Indian Standard alltotal1 = api.column(13, { page: 'current' }).data().reduce(function(a, b) { return intVal(a) + intVal(b); }, 0); alltotal1 = alltotal1.toLocaleString('en-IN', { minimumFractionDigits: 2 }); alltotal2 = api.column(14, { page: 'current' }).data().reduce(function(a, b) { return intVal(a) + intVal(b); }, 0); alltotal2 = alltotal2.toLocaleString('en-IN', { minimumFractionDigits: 2 }); difference1 = intVal(alltotal1) - intVal(alltotal2); // $difference = number_format($difference1, 2, '.', ''); difference = difference1.toLocaleString(undefined, { minimumFractionDigits: 2 }); // Update footer on top between DOM Elements $("div.toolbar").html('
' + '\n' + '
Total Debit Amount  :   ' + alltotal1 + '
Total Credit Amount  :   ' + alltotal2 + '
'); }, }); //datatable close var buttons = new $.fn.dataTable.Buttons(table, { buttons: [{ extend: "collection", alignment: 'right', text: '  Tools', buttons: [{ extend: "print", footer: true, orientation: 'landscape', messageBottom: '' + '
' + '
' + 'This is a system generated report.' + '
' + '
' + $('#isoformat').text() + '' + '
', prefix: ["Line One", "", "Line Two", "", "Line Three"], pageSize: 'A4', text: '  Print', title: 'ESM | List of ', filename: 'ESM | List of Cash Entries', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15], stripHtml: false }, messageTop: function() { return $("div.toolbar").html(); }, customize: function(win) { $(win.document.body).find('table tbody td:nth-child(1)').css('text-align', 'center'); $(win.document.body).find('table tbody td:nth-child(2)').css('text-align', 'center'); $(win.document.body).find('table tbody td:nth-child(3)').css('vertical-align', 'middle'); $(win.document.body).find('table tbody td:nth-child(4)').css('vertical-align', 'middle'); $(win.document.body).find('table tbody td:nth-child(5)').css('vertical-align', 'middle'); $(win.document.body).find('table tbody td:nth-child(6)').css('vertical-align', 'middle'); $(win.document.body).find('table tbody td:nth-child(7)').css('vertical-align', 'middle'); $(win.document.body).find('table tbody td:nth-child(8)').css('text-align', 'right'); $(win.document.body).find('table tbody td:nth-child(9)').css('text-align', 'right'); $(win.document.body).find('table tbody td:nth-child(10)').css('text-align', 'right'); $(win.document.body).find('table tbody td:nth-child(11)').css('text-align', 'right'); } }, { extend: "copyHtml5", text: '  Copy', messageBottom: '\n\n This is a system generated report.', title: 'ESM | List of ', filename: 'ESM | List of Cash Entries', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15] } }, { extend: "excelHtml5", text: '  Excel', messageBottom: '\n\n This is a system generated report.', title: 'ESM | List of ', filename: 'ESM | List of Cash Entries', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15] } }, { extend: "csvHtml5", text: '  CSV', // title: 'Customized CSV Title', messageBottom: '\n\n This is a system generated report.', title: 'ESM | List of ', filename: 'ESM | List of Cash Entries', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15] } }, { extend: "pdfHtml5", margin: [0, 0, 0, 0], text: '  PDF', filename: 'ESM | List of Cash Entries', title: 'ESM | List of ', orientation: 'portrait', // landscape exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15], stripNewlines: false }, messageBottom: { text: '\n\n This is a system generated report.', fontSize: 8, bold: true, italics: true, alignment: 'center' }, messageTop: function() { return 'ESM | List of ' + '\n\n' + $("div.toolbar").text(); }, customize: function(doc) { //Remove the title created by datatTables doc.content.splice(0, 1); //Create a date string that we use in the footer. Format is dd-mm-yyyy var now = new Date(); var jsDate = now.getDate() + '-' + (now.getMonth() + 1) + '-' + now.getFullYear() + ' @' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds(); // Logo converted to base64 var companylogo = logo1; //console.log('RESULT2', companylogo); doc.pageMargins = [20, 60, 20, 30]; // Set the font size fot the entire document doc.defaultStyle.fontSize = 7; // Set the fontsize for the table header doc.styles.tableHeader.fontSize = 7; // Create a header object with 3 columns // Left side: Logo // Middle: brandname // Right side: A document title doc.styles.title = { color: 'red', fontSize: '40', background: 'blue', alignment: 'center' } doc.styles.title.alignment = "right"; doc.styles.message = { color: 'black', fontSize: '10', alignment: 'center' } var rowCount = doc.content[1].table.body.length; for (i = 1; i < rowCount; i++) { doc.content[1].table.body[i][0].alignment = 'center'; doc.content[1].table.body[i][1].alignment = 'center'; doc.content[1].table.body[i][2].alignment = 'left'; doc.content[1].table.body[i][3].alignment = 'left'; doc.content[1].table.body[i][4].alignment = 'left'; doc.content[1].table.body[i][5].alignment = 'left'; doc.content[1].table.body[i][6].alignment = 'center'; doc.content[1].table.body[i][7].alignment = 'center'; doc.content[1].table.body[i][8].alignment = 'right'; doc.content[1].table.body[i][9].alignment = 'right'; doc.content[1].table.body[i][10].alignment = 'right'; doc.content[1].table.body[i][11].alignment = 'right'; } doc['header'] = (function() { return [{ columns: [{ image: companylogo, width: 34, height: 20 }, { alignment: 'left', italics: true, text: company, fontSize: 12, margin: [10, 5] }, { alignment: 'right', fontSize: 5, text: { text: address + '\n' + address2 + '\n' + city + ',' + country + '\n' + mob + '\n' + web }, } ], margin: [10, 10, 10, 10] }, { margin: [0, 0, 0, 0], canvas: [{ type: 'line', x1: 15, y1: 0, x2: 840 - 10, y2: 0, lineWidth: 0.5 }] } ]; }); // Create a footer object with 2 columns // Left side: report creation date // Right side: current page and total pages doc['footer'] = (function(page, pages) { return { columns: [{ alignment: 'left', text: ['Printed on: ', { text: jsDate.toString() }] }, { alignment: 'center', text: [{ text: isoformat.toString() }] }, { alignment: 'right', text: ['page ', { text: page.toString() }, ' of ', { text: pages.toString() }] } ], margin: 20 }; }); // Change dataTable layout (Table styling) // To use predefined layouts uncomment the line below and comment the custom lines below doc.content[0].layout = 'lightHorizontalLines'; // noBorders , headerLineOnly var objLayout = {}; objLayout['hLineWidth'] = function(i) { return 0.5; }; objLayout['vLineWidth'] = function(i) { return 0.5; }; objLayout['hLineColor'] = function(i) { return 'green'; }; objLayout['vLineColor'] = function(i) { return 'red'; }; objLayout['paddingLeft'] = function(i) { return 4; }; objLayout['paddingRight'] = function(i) { return 4; }; //doc.content[0].layout = objLayout; }, }, { extend: "colvis", text: '  Display Columns', //text: 'Column Selection', messageBottom: '\n\n This is a system generated report.', collectionLayout: "fixed two-column", collectionTitle: "Select Columns to Display", postfixButtons: ["colvisRestore"], columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], columnText: function(dt, idx, title) { return idx + 1 + ": " + title; } }, { text: '  Export Database', action: function(e, dt, button, config) { window.location = 'cash_entry_export.php'; } } ] }] }).container().appendTo($('#tools')); $('#btnGo').click(function() { var start_date = $('#from_datepicker').val(); var end_date = $('#to_datepicker').val(); if (start_date != '' && end_date != '') { // $('#example').dataTable(); // $('#example').dataTable().destroy(); fetch_data('yes', start_date, end_date); // table.destroy(); table.draw(); } else { alert("Both Date is Required"); } }); } //function fetch_data });