php + jqgrid + export to excel

后端 未结 6 1542
长情又很酷
长情又很酷 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:45

    Here is a clever solution to save the jqGrid data as excel sheet without calling the php script: (You just need to call this function with GridID and an optional Filename)

    var createExcelFromGrid = function(gridID,filename) {
        var grid = $('#' + gridID);
        var rowIDList = grid.getDataIDs();
        var row = grid.getRowData(rowIDList[0]); 
        var colNames = [];
        var i = 0;
        for(var cName in row) {
            colNames[i++] = cName; // Capture Column Names
        }
        var html = "";
        for(var j=0;j

    We first create a CSV string delimited with ;. Then an anchor tag is created with certain attributes. Finally click is called on a to download the file.

    You could have a look at several excel MIME Types : MIME Type List

提交回复
热议问题