Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Providing custom filename is not working in table2excel jquery?

i have used jquery code to export table data into excel file, got code from here

but providing custome file name is not working it is taking random filename.
how to provide custom file name from code.

<script>
$(function() {
        $("button").click(function(){
        $("#example").table2excel({
                exclude: ".noExl",
        name: "Employee"
        }); 
         });
});
</script>
like image 578
Yugal Avatar asked Feb 07 '15 08:02

Yugal


1 Answers

1.Open jquery.table2excel.js

2.Find function getFileName(settings)

3.Change it to

function getFileName(settings) {
        return ( settings.filename ? settings.filename : settings.name ) +
               ( settings.fileext ? settings.fileext : ".xls" );
}

settings.name is variable from your custom js scripts when u call jquery2excel In my example it looks like

$(".generateXLS").click(function(){
    var idOfTable = $(this).attr("data-rel");
    var tableName = $(this).attr("data-table-name");
    $("#tableN"+idOfTable).table2excel({
        name: tableName
    }); 
});
like image 66
dawid9692 Avatar answered Nov 01 '22 18:11

dawid9692