php + jqgrid + export to excel

后端 未结 6 1547
长情又很酷
长情又很酷 2020-12-08 05:19

Somebody knows a way to export the data from a jqgrid to excel?

I want to do a report using this jqgrid that i think is awsome. But i need to save or print this rep

6条回答
  •  孤城傲影
    2020-12-08 05:51

    This is my approach, just add this code to your js/html file

    $("#list").jqGrid('navGrid', '#pager',{view:true, del:false, add:false, edit:false, excel:true})
                    .navButtonAdd('#pager',{
                                    caption:"Export to Excel", 
                                    buttonicon:"ui-icon-save", 
                                    onClickButton: function(){ 
                                      exportExcel();
                                    }, 
                                    position:"last"
                                });
    
            function exportExcel()
            {
                var mya=new Array();
                mya=$("#list").getDataIDs();  // Get All IDs
                var data=$("#list").getRowData(mya[0]);     // Get First row to get the labels
                var colNames=new Array(); 
                var ii=0;
                for (var i in data){colNames[ii++]=i;}    // capture col names
                var html="";
                for(i=0;i

    PHP script

    header('Content-type: application/vnd.ms-excel');
    header("Content-Disposition: attachment; filename=file.xls");
    header("Pragma: no-cache");
    
    $buffer = $_POST['csvBuffer'];
    
    try{
        echo $buffer;
    }catch(Exception $e){
    
    }
    

提交回复
热议问题