ColVis And Table tools in single datatable:

Data tables makes our work very easy with many extensions like table tools and Colvis
but if we want to use both at a time it is difficult(to know to add table tools and ColVis to your data table please follow my previous post regarding Data Table and Table tools)

I tried and searched for many blog and sites how to use both table tools and ColVis in one datatable and found the solution to it so taught it might save time for others like me

Add the following script to achieve both extensions:
1.script for table tools:

$('#example1').DataTable( {
 "sDom": 'T<"clear">lfrtip',
   "oTableTools": {
    "sSwfPath":       "${request.getContextPath()}/theme/script/datatable/copy_csv_xls_pdf.swf",
       "aButtons": ["csv", "xls", "pdf", "print"]
       }
       });
2. Script for ColVis:
$(document).ready(function() {
   $('#example').DataTable( {
       "dom": 'C<"clear">lfrtip',
       "colVis": {
           "buttonText": "Change columns"
       }
   } );
} );


3.Script to add both extensions:
$(document).ready(function() {
   $('#example').DataTable( {
                         "sDom": 'TC<"clear">lfrtip',
              "colVis": {
                      "buttonText": "Change columns"
                      }
                    "oTableTools": {
                 "sSwfPath":       "${request.getContextPath()}/theme/script/datatable/copy_csv_xls_pdf.swf",
                  "aButtons": ["csv", "xls", "pdf", "print"]
               }          
   } );
} );

No comments:

Post a Comment