How to change export file name in data tables?

 $("#dataTable").DataTable({                    
                    dom: 'Bfrtip',
                    buttons: [
                             { extend: 'excel', text:'export to excel',title:'1'},
                    ],
})

I can change the button text for the following code, but I can not get the title property.

var table= $("#dataTable").DataTable();
tabele.button(0).text('excel');
+4
source share
2 answers

after it has been set in the object, and the initialized datatable cannot be changed. you can set it dynamically from a page element in init, but.

("#dataTable").each( function(index) {
    var exportTitle = $("#somePageElement").text();
    $(this).DataTable({
        dom: 'Bfrtip',
        buttons: [
            {
                extend: 'excel',
                title: exportTitle 
            },
            {
                extend: 'pdf',
                title: exportTitle 
            }
        ]
    });

This post has a good suggestion on how to handle this. Configuring custom datatables export excelHtml5 file name with selected text

+2
source

, -, , .

CSV :

 $("#dataTable").DataTable({                    
    dom: 'Bfrtip',
    buttons: [
        {extend: 'csv', 
        text:'export to csv',
        title:'1',
        action: function(e, dt, button, config) {
        config.title = "New title";

        // This checks whether the HTML5 or flash version needs
        // to be called, so it not needed if the button you are using 
        // doesn't have that distinction
        if ($.fn.dataTable.ext.buttons.csvHtml5.available( dt, config )) {
            $.fn.dataTable.ext.buttons.csvHtml5.action(e, dt, button, config);
        }
        else {
            $.fn.dataTable.ext.buttons.csvFlash.action(e, dt, button, config);
        }
    }}
    ]
})
+2

Source: https://habr.com/ru/post/1623635/


All Articles