1
var counter = 0;
function staticVar()
{
    if (staticVar.counter == undefined)
    {
        staticVar.counter = 1
    }
    else
    {
        staticVar.counter++
    }
    return staticVar.counter;
}



//Our table has horizontal and vertical scroll bars and the first columni.e, the serial number will be fixed when scrolling
$(document).ready(function() {
    var download_file_counter= staticVar();
    var table = $('#example').DataTable({
        "aoColumnDefs": [{ "bSortable": false, "aTargets": [0] }],
        scrollY: '40vh',
        scrollX: '40vh',
        paging: true,
        pageLength: 20,
        lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
        dom: 'Bflrtip',
        buttons: [{
            extend: 'print',
                exportOptions: {
                columns: ':visible'
                }
            },            
            {            
                extend: 'colvis',
                className: 'colvisButton'
            },
            {                
                extend: 'excelHtml5',
                title: 'LicenseDetails_'+(++download_file_counter)+'_'+today,                            
                text: 'Excel',
                exportOptions: {                  
                    modifier: {
                    page: 'current'
                }
             }
         }],
         columnDefs: [{
             targets: -1,
             visible: false,
             orderable: false
         }],
         order: [[ 1, 'asc' ]]
    });
    download_file_counter= makeCounter();
    $('#start-date, #end-date').change(function () {
        table.draw();
    });
    $('#start-date1, #end-date1').change(function () {
        table.draw();
    });
    $('#start-date2, #end-date2').change(function () {
        table.draw();
    });              
});

This is my javascript code I want to pass the counter variable to the filename on clicking of the excel button. The counter is not incrementing for onclick of that.

Vlad Iobagiu
  • 4,118
  • 3
  • 13
  • 22
Shilpa
  • 19
  • 4
  • I don't this this is possible with bootstrap data table check this post http://stackoverflow.com/a/31786442/6687096 . I think you need to write custom event for that excel button. – kernal_lora Aug 31 '16 at 05:05
  • Thank you kernal lora i will check it – Shilpa Aug 31 '16 at 05:24

0 Answers0