jquery - php + jqgrid + export to excel -
Is there a way to export data from jqgrid to Excel?
I report this using a jqgrid which I think is weird but I need to save or print this report in some way, because information is kept. Does anybody know anyway ??
This is my view, just add this code to your js / html file JqGrid ('navGrid', '#pager', {visible: true, del: wrong, add: wrong, edit: wrong, excel: true}
) .NavButtonAdd ('#pager', {caption: "Export to Excel ", Buttonon:" UI-icon-save ", onclick button: function () {exportExcel ();}, position:" last "}); Function Export Excl () {var mya = New Array (); My = $ ("# list") getDataIDs () .; // Get all IDs var data = $ ("#list"). GetRowData (mya [0]); Get the first line to get // labels var colNames = new Array (); Var ii = 0; (Var i in data) {colNames [ii ++] = i;} // capture call name var html = ""; (I = 0; i & lt; mya.length; i ++) for {data = $ ("#list"). GetRowData (Maya [i]); // for each line (j = 0; j & lt; colNames.length; j ++) {html = html + data [colNames [j]] + "\ t"; // Output delimited as each column) html = html + "\ n"; // output each row at the end of the line} html = html + "\ n"; // End the end of the line on the document. Form [0] .csvBuffer.value = html; Document.forms [0] = 'Post' .method; Document.forms [0] .action = 'csvExport.php'; // send it to the server which will open this content in excel file document.forms [0] .target = '_ blank'; Document.forms [0] .submit (); }
PHP script
header ('content-type: application / vnd.ms-excel'); Header ("content-dispute: attachment; file name = file.xls"); Header ("Prestama: no-cache"); $ Buffer = $ _POST ['CSV buffer']; {Echo $ buffer; } Hold (exception $ E) {}
Comments
Post a Comment