Data Tables download xls/csv file not working properly -


i want have 3 buttons - download csv, xls , pdf file. in case when click on download csv file button, saves extension of csv file, when open it excel - it's not comma separated file. pdf download button working correctly. xls button not work - it's not clickable @ all. tried write code:

"tabletools": {      "abuttons": [ {           "sextends":    "download",           "sbuttontext": "download xls",           "surl":        "/generate_xls.php"       }]  } 

but each button download excel file.

here's code:

<html>  <head>  <link rel="stylesheet" href="//cdn.datatables.net/1.10.5/css/jquery.datatables.min.css" type="text/css"  />    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>  <script src="//cdn.datatables.net/1.10.5/js/jquery.datatables.min.js"></script>  <script src="https://www.datatables.net/release-datatables/media/js/jquery.js"></script>  <script src="https://www.datatables.net/release-datatables/media/js/jquery.datatables.js"></script>  <script src="https://www.datatables.net/release-datatables/extensions/tabletools/js/datatables.tabletools.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.2.0/zeroclipboard.core.min.js"></script>  <link rel="stylesheet"   href="https://www.datatables.net/release-datatables/media/css/jquery.datatables.css" type="text/css" />  <script>  $(document).ready(function() {      $('#example').datatable( {          "pagingtype": "full_numbers",           "bsort": true,           "sdom": 't<"clear">lfrtip',  	     "tabletools": {  	    "sswfpath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf",        		abuttons: [      { sextends: "csv",        sfilename: 'download.csv',        sfieldseperator: ","       },      { sextends: "xls",        sfilename: 'download.xls'      },      { sextends: "pdf",        sfilename: 'download.pdf'      }     ]   	}          } );  } );  </script>    <script>  $(document).ready(function() {      // setup - add text input each footer cell      $('#example tfoot th').each( function () {          var title = $('#example thead th').eq( $(this).index() ).text();          $(this).html( '<input type="text" placeholder="Търси '+title+'" />' );      } );         // datatable      var table = $('#example').datatable();         // apply search      table.columns().eq( 0 ).each( function ( colidx ) {          $( 'input', table.column( colidx ).footer() ).on( 'keyup change', function () {              table                  .column( colidx )                  .search( this.value )                  .draw();          } );      } );  } );  </script>  <script>    </script>  </head>  <body>  <div class='col-md-8' id='student_results'>  <br/><br/>    <table  id='example'>   <thead>    	<tr><th>Потребител</th><th>Училище</th><th>Клас</th><th>Анкета</th><th>Въпрос</th><th>Отговор</th></tr>    </thead>      <tfoot>              <tr>                  <th>Потребител</th>                  <th>Училище</th>                  <th>Клас</th>                  <th>Анкета</th>                  <th>Въпрос</th>                  <th>Отговор</th>              </tr>          </tfoot>     <tbody>    <?php     foreach ($student_results $row)  {    ?>  	<tr><td>  	<?php echo $row->username; ?>  	</td><td>  	<?php echo $row->school; ?>  	</td><td>  	<?php echo $row->class; ?>  	</td><td>  	<?php echo $row->survey_id; ?>    	</td><td>    	<?php echo $row->question_id; ?>    	</td><td>    	<?php echo $row->answer; ?>    	</td></tr>    	<?php    }   ?>  	  	</table>    	<table border='1' id='example'>  	<tr><th>Въпрос</th><th>Среден резултат</th></tr>  <?php  foreach ($average_results $row)  {  ?>  	    	<td>    	<?php echo $row->question_id ; ?>    	</td><td>    	<?php echo round("$row->answer",2); ?>    	</td></tr>    	<?php  }  ?>  </tbody>  	</table>        	</div>  	</body>  	</html>

you need target desired buttons, when using approach. having "xls" breaks up.

abuttons: [     { sextends: "csv",       sfilename: 'download.csv',       sfieldseperator: "," //<--- example of how set delimiter     },     { sextends: "xls",       sfilename: 'download.xls'     },     { sextends: "pdf",       sfilename: 'download.pdf'     }    ]  

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -