Export JQgrid data to excel

 I am wondering like if you find the solution for (

If I like to export all data (e.g. totally 18 records, 10 displayed in current grid and 8 in second grid page), is there a way to capture all 18 records without invoking the backend?)

because mine also the same problem,i am not finding any solution only first page data is capturing in excel …

This is my ExportJQGridDataToExcel.js function

 

function ExportJQGridDataToExcel(tableCtrl, excelFilename) {

var allJQGridData = $(tableCtrl).jqGrid(‘getGridParam’,
‘data’);

// var allJQGridData = $(tableCtrl).jqGrid(‘getRowData’);

var jqgridRowIDs = $(tableCtrl).getDataIDs();

var
headerData = $(tableCtrl).getRowData(jqgridRowIDs[0]);

var columnNames =
new Array();

var
columnHeaders =
new Array();

var
inx = 0;

var
allColumnNames = $(tableCtrl).jqGrid(
‘getGridParam’,
‘colNames’).slice();

allColumnNames.splice(0, 1);

for
(
var headerValue
in headerData) {

var isColumnHidden = $(tableCtrl).jqGrid("getColProp",
headerValue).hidden;

if
(!isColumnHidden && headerValue !=
null) {

columnNames.push(headerValue);

columnHeaders.push(allColumnNames[inx]);

}

inx++;

}

var
excelData =
;

for
(
var k = 0; k < columnNames.length; k++) {

excelData += columnHeaders[k] +"t";

}

excelData = removeLastChar(excelData) +"rn";

var
cellValue =
;

for
(i = 0; i < allJQGridData.length; i++) {

var
data = allJQGridData[i];

for
(
var j = 0; j < columnNames.length; j++) {

cellValue = + data[columnNames[j]];

if
(cellValue ==
null)

excelData +="t";

else
{

if
(cellValue.indexOf(
"a href") > -1) {

cellValue = $(cellValue).text();

}

cellValue = cellValue.replace(/‘/g, "&apos;");

excelData += cellValue +"t";

}

}

excelData = removeLastChar(excelData) +"rn";

}

postAndRedirect("/Helpers/ExportGridToExcel.ashx?filename="
+ excelFilename, { excelData: excelData });

}

 

Plz help me out…..

here is a link with your answer and all the code you need:

http://www.codeproject.com/Articles/784342/Export-data-from-jqGrid-into-a-real-Excel-file

Hi lucidcrew,

                    I already saw that link,but there is no code on

ExportJQGridDataToExcelfunction.

He just mentioned as like below..

If you have a look at the

ExportJQGridDataToExcel

function, you’ll find that it iterates through the rows of data in your

jqGrid

, and builds one (large ?) tab-separated variable containing all of your

jqGrid

‘s data, plus a header row.

It then calls the

ExportGridToExcel.ashx

handler, but as a “POST” call, so it can pass this (potentially large) set of data to the handler.

Once the data arrives at the handler, we’re back on the server-side, and can easily convert this into a

DataTable

, and call my "Export to Excel" class to create the Excel file.

                   

Hi mcfarlandparkway,

I had tried a similar example, this may help you, please try other’s code as below.

function to be called inside of your onclick event.

function exportGrid(){

  mya = $("#" + table).getDataIDs(); // Get All IDs

var data = $("#" + table).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 = "<html><head>"

        + "<style script=&quot;css/text&quot;>"

        + "table.tableList_1 th {border:1px solid black; text-align:center; "

        + "vertical-align: middle; padding:5px;}"

        + "table.tableList_1 td {border:1px solid black; text-align: left; vertical-align: top; padding:5px;}"

        + "</style>"

        + "</head>"

        + "<body style=&quot;page:land;&quot;>";

for ( var k = 0; k < colNames.length; k++) {

    html = html + "<th>" + colNames[k] + "</th>";

}

html = html + "</tr>"; // Output header with end of line

for (i = 0; i < mya.length; i++) {

    html = html + "<tr>";

    data = $("#" + table).getRowData(mya[i]); // get each row

    for ( var j = 0; j < colNames.length; j++) {

     html = html + "<td>" + data[colNames[j]] + "</td>"; // output each Row as

                // tab delimited

    }

    html = html + "</tr>"; // output each row with end of line

}

html = html + "</table></body></html>"; // end of line at the end

alert(html);

html = html.replace(/'/g, '&apos;');

//  var form = "<form name='pdfexportform' action='generategrid' method='post'>";

//  form = form + "<input type='hidden' name='pdfBuffer' value='" + html + "'>";

//  form = form + "</form><script>document.pdfexportform.submit();</sc"

//      + "ript>";

//  OpenWindow = window.open('', '');

//  OpenWindow.document.write(form);

//  OpenWindow.document.close();

}

For more information, please refer to link below.

http://stackoverflow.com/questions/21494761/how-to-enable-jqgrid-to-export-data-into-pdf-excel

This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore,
Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you
completely understand the risk before retrieving any software from the Internet.

 Best regards,

Aswecan

Leave a Reply