Home Forums Porto Admin Template Datatable tools – Excel export problem

This topic contains 5 replies, has 2 voices, and was last updated by  Support2 2 months, 2 weeks ago. This post has been viewed 146 times

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10027422

    fl-330
    Participant

    Hello

    I hava a datatable with the following tools : ‘copy’, ‘print’, ‘excel’, ‘csv’, ‘pdf’

    One of the table columns contains 20 digit numbers.
    When Copying or Exporting the table data in Excel the value of the columns is truncated to 15 digits and zerofilled to 20.

    This behaviour doesn’t occur when exporting in pdf or csv.

    Any help would be very appreciated.

    Best regards



    Template Version: 2.1.1
    #10027428

    Support2
    Keymaster

    Hello,

    This seems to be a limitation with Excel that has the limit of 15 numbers.
    But exists an workaround to fix this problem. Please go to your (js/examples/examples.datatables.tabletools.js) and replace all the code with that: https://pastebin.com/raw/9H7R2Unx

    Please, try this and let me know if you need further assistance.

    Kind Regards,

    Rodrigo.


    #10027433

    fl-330
    Participant

    Hello Rodrigo

    Thanks a lot, that did the trick.

    A last thing, How to make the pdf generated in lanscape mode ?

    Here is below my actual js :

    (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: ['print', 'pdf', 'csv', {
    				extend: 'excelHtml5',
    				customizeData: function(data) {
    					for(var i = 0; i < data.body.length; i++) {
    					for(var j = 0; j < data.body[i].length; j++) {
    						data.body[i][j] = '\u200C' + data.body[i][j];
    					}
    					}
    				},      
    				orientation: 'landscape'
    			}],
    			oLanguage: {
    			    "sEmptyTable":     "Aucun produit dans ce BL",
    			    "sInfo":           "_START_ &agrave; _END_ sur un total de _TOTAL_ enregistrements",
    			    "sInfoEmpty":      "Affichage 0 a 0 sur 0 produits",
    			    "sInfoFiltered":   "(Filtre sur _MAX_ total enregistrements)",
    			    "sInfoPostFix":    "",
    			    "sInfoThousands":  ",",
    			    "sLengthMenu":     "_MENU_ enregistrements",
    			    "sLoadingRecords": "Chargement...",
    			    "sProcessing":     "Traitement...",
    			    "sSearch":         "",
    			    "sZeroRecords":    "La requete n'a retourn&eacute; aucun r&eacute;sultat",
    			    "oPaginate": {
    			        "sFirst":    "Premier",
    			        "sLast":     "Dernier",
    			        "sNext":     "Suivant",
    			        "sPrevious": "Pr&eacute;c&egrave;dent" 
    			    },
    			    "oAria": {
    			        "sSortAscending":  ": activate to sort column ascending",
    			        "sSortDescending": ": activate to sort column descending" 
    			    }
    			}
    		});
    
    		$('<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]);

    #10027459

    Support2
    Keymaster

    Hello,

    You can do this with only a few adjustments, here is the code you need:
    https://pastebin.com/raw/Mr1N07ed

    Please, try this and let me know if you need further assistance.

    Kind Regards,

    Rodrigo.


    #10027464

    fl-330
    Participant

    Thank you very much Rodrigo !

    It worked.

    Best regards


    #10027471

    Support2
    Keymaster

    Hello,

    Great!

    If you need further assistance, feel free to contact us.

    Kind Regards,

    Rodrigo.


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