Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

jquery - issue with downloading all redords from server side yajra datatable

I want to download all records from server side yajra datatable as pdf and excel format and not only particular page for that I have make below code

var table = $('.dataTables-example').DataTable({
    "aaSorting": [],
    destroy: true,
    pageLength: 25,
    responsive: true,
    // processing: true,
    serverSide: true,
    dom: '<"html5buttons"B>lTftigp', 
    buttons: 
    [
        { 
            extend: 'copy',
            footer: true
        },
        {
            extend: 'csv',
            footer: true
        },
        {
            extend: 'excel', title: 'Customer Sales Rep Sales Totals',
            footer: true,
            action: newExportAction
        },
        { 
            extend: 'pdfHtml5',  title: 'Customer Sales Rep Sales Totals', orientation: 'landscape',
            exportOptions: 
            {
                columns: ':visible',
                search: 'applied',
                order: 'applied',
                modifier: 
                {
                    pageMargins: [ 0, 0, 0, 0 ], // try #3 setting margins
                    margin: [ 10,0 ], // try #4 setting margins
                    alignment: 'center'
                }, 
                body: 
                {
                    margin:[10,0],
                    pageMargins: [ 0, 0, 0, 0 ],
                    alignment: 'center'
                }, 
                columns: [0,1,2,3,4,5,6,7] //column id visible in PDF    
            },
            customize: function (doc) 
            {                       
                //doc.content.splice(0,1);
                doc.content[1].table.widths = ['10%','10%','10%','10%','15%','15%','15%','15%'];
                doc.content[1].borders = ['2px solid'];

                /* doc.content[1].table.widths =
                                Array(doc.content[1].table.body[1].length + 1).join('*').split('');*/

                doc.content.splice(0,0);

                //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();
                
                var logo = 'logo.png';
                
                doc.pageMargins = [20,60,20,30];

                // Set the font size fot the entire document
                doc.defaultStyle.fontSize = 8;
                /*doc.defaultStyle.width=100;*/
                // Set the fontsize for the table header
                doc.styles.tableHeader.fontSize = 10;
                doc.styles.tableHeader.alignment = 'left';
                
                doc['header']=(function() {
                    return {
                        columns: [
                            {
                                image: logo,
                                width: 80
                            },
                        ],
                        margin: 20,
                        width:100
                    }
                });
            
                doc['footer']=(function(page, pages) {
                    return {
                        columns: [
                            {
                                alignment: 'left',
                                text: ['Created on: ', { text: jsDate.toString() }]
                            },
                            {
                                alignment: 'right',
                                text: ['page ', { text: page.toString() },  ' of ', { text: pages.toString() }]
                            }
                        ],
                        margin: 20
                    }
                });
            
                var objLayout = {};
                objLayout['hLineWidth'] = function(i) { return .100; };
                objLayout['vLineWidth'] = function(i) { return .100; };
                objLayout['hLineColor'] = function(i) { return '#aaa'; };
                objLayout['vLineColor'] = function(i) { return '#aaa'; };
                objLayout['paddingLeft'] = function(i) { return 0; };
                objLayout['paddingRight'] = function(i) { return 0; };
                objLayout['alignment'] = function(i) { return 'center'; };
                doc.content[0].layout = objLayout;
            }
        },
        {
            extend: 'print', text : 'Print Preview',
            exportOptions: 
            {
                columns: ':not(.no-export)'
            },
            customize: function (win)
            {
                $(win.document.body).addClass('white-bg');
                $(win.document.body).css('font-size', '10px');
        
                $(win.document.body).find('table')
                        .addClass('compact')
                        .css('font-size', 'inherit');

                $(win.document.body).find('image')
                        .addClass('img')
                        .css('height', '50');                                               
            }
        }
    ],
    ajax: {
        url:'{{ route("admin.ajaxCustomerSalesRepTotal") }}',
        method:'post',
        data: { srch_start_date: srch_start_date, srch_end_date : srch_end_date },
    },
    columns : [
        {data : 'total_sales', name : 'total_sales'},
        {data : 'total_orders', name : 'total_orders'},
        {data : 'account_number', name : 'account_number'},
        {data : 'account_suffix', name : 'account_suffix'},
        {data : 'sales_rep_id', name : 'sales_rep_id'},
        {data : 'sales_last_name', name : 'sales_last_name'},
        {data : 'sales_first_name', name : 'sales_first_name'},
        {data : 'sales_state_name', name : 'sales_state_name'},
    ],
});
question from:https://stackoverflow.com/questions/65856649/issue-with-downloading-all-redords-from-server-side-yajra-datatable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...