How to export Index column using DataTable TableTool plugin.

How to export Index column using DataTable TableTool plugin.

Manendra1982Manendra1982 Posts: 1Questions: 1Answers: 0

Hi I am using dataTables.tableTools.js for exporting DataTable columns. all columns are returning from database for displaying on DataTable including index column which display row numbers. I am generating row number under index column using jquery,when i export my datatable then its exporting all column with proper data.but its exporting index column without row numbers.

This question has an accepted answers - jump to answer

Answers

  • indu11indu11 Posts: 4Questions: 2Answers: 0

    Hello i am also have same issue.Can anyone help?

  • ananddotworkananddotwork Posts: 1Questions: 0Answers: 0
    edited February 2017

    i too having same issue, generating serial number using this code

    t.on('order.dt search.dt buttons.dt', function () {
    t.column(0, {search:'applied', order:'applied', buttons:'applied'}).nodes().each( function (cell, i) {
    cell.innerHTML = i+1;
    });
    }).draw();

    When exporting serial number missing in exported file(excel or pdf or print or csv)

  • JazMagnoJazMagno Posts: 2Questions: 0Answers: 1

    After days of tries i get this solution:

    You need add this event also of what you mention.

    t.on('draw',function(){
          t.rows({search:'applied', order:'applied', filter : 'applied'}).data().each(function(d,i){
               d[0]=i+1;
          });
    });
    
  • JazMagnoJazMagno Posts: 2Questions: 0Answers: 1
    edited January 2018 Answer ✓

    Hi again, i find another better solution:

    t.on('order.dt search.dt', function () {
         t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
               cell.innerHTML = i+1;
               t.cell(cell).invalidate('dom');
         });
    }).draw();
    

    In the settings of table i have:

    var t=$('#id_table').DataTable({
           dom: 'Bfrtip',
           buttons: [
                    {
                        extend: 'excel',
                        exportOptions: {
                            columns: ':visible'
                        }
                    },{
                        extend: 'pdf',
                        orientation: 'landscape',
                        pageSize: 'LEGAL',
                        exportOptions: {
                            columns: ':visible'
                        }
                    },{
                        extend: 'print',
                        text: 'Imprimir',
                        exportOptions: {
                            columns: ':visible'
                        },
                        autoPrint: true
                    },{
                        extend: 'colvis',
                        text: 'Columnas visibles'
                    }
                ]
    });
    
This discussion has been closed.