I had the same problem, and since the new format (maybe not supported by each browser) <a download=""></a> , it worked fine for me. This directly uses HTML / Javascript without part of the PHP server, because using a submit form is too heavy for large data tables.
- change
<button> to <a> - no more than
window.open() - using the basic behavior
<a> (therefore, no more than e.preventDefault() ), but changing href to data:blabla and adding download="filename" :
<div id="example" class="k-content"> <a href="#" id="btnExport" >Export to csv!</a> <div id="grid"></div> </div> <script> $("#btnExport").click(function (e) { var result = "data:application/vnd.ms-excel,"; this.href = result; this.download = "my-custom-filename.xls"; return true; }); </script>
source share