Home Forums Porto Admin Template Datatables PDF width

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10031016
    mushi
    Participant

    Hello,
    Im using datatable tools for generating pdf/execl, but my table’s width in pdf file is not 100%.
    Image

    please help me to fix this!



    Template Version: 2.2.0
    #10031024
    Support2
    Keymaster

    Hello Mushi,

    Please try changing the code in js/examples/examples.datatables.tabletools.js to:

    (function($) {
    
    	'use strict';
    
    	var datatableInit = function() {
    		var $table = $('#datatable-tabletools');
    
    		var table = $table.dataTable({
    			sDom: '<"text-right mb-md"T><"row"<"col-lg-6"l><"col-lg-6"f>><"table-responsive"t>p',
    			buttons: [
    				{
    					extend: 'print',
    					text: 'Print'
    				},
    				{
    					extend: 'excel',
    					text: 'Excel'
    				},
    				{
    					extend: 'pdf',
    					text: 'PDF',
    					customize : function(doc){
    			            var colCount = new Array();
    			            $('#datatable-tabletools').find('tbody tr:first-child td').each(function(){
    			                if($(this).attr('colspan')){
    			                    for(var i=1;i<=$(this).attr('colspan');$i++){
    			                        colCount.push('*');
    			                    }
    			                }else{ colCount.push('*'); }
    			            });
    			            doc.content[1].table.widths = colCount;
    			        }
    				}
    			]
    		});
    
    		$('<div />').addClass('dt-buttons mb-2 pb-1 text-right').prependTo('#datatable-tabletools_wrapper');
    
    		$table.DataTable().buttons().container().prependTo( '#datatable-tabletools_wrapper .dt-buttons' );
    
    		$('#datatable-tabletools_wrapper').find('.btn-secondary').removeClass('btn-secondary').addClass('btn-default');
    	};
    
    	$(function() {
    		datatableInit();
    	});
    
    }).apply(this, [jQuery]);

    Please try that and let us know if you need further assistance.

    Kind Regards,

    Rodrigo.


    #10031028
    mushi
    Participant

    Thankyou so much Rodrigo it worked! 🙂


Viewing 3 posts - 1 through 3 (of 3 total)