Forum
I use the following javascript function from my code to export the jQGrid data. This works for me. I use a JSP to open the excel. Same code can be simulated in PHP also. Hope someone will benefit from this snippet
function export1()
{
var mya=new Array();
mya=jQuery("#list2").getDataIDs(); // Get All IDs
var data=jQuery("#list2").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<mya.length;i++)
{
data=jQuery("#list2").getRowData(mya[i]); // get each row
for(j=0;j<colNames.length;j++)
{
html=html+data[colNames[j]]+"\\t"; // output each column as tab delimited
}
html=html+"\\n"; // output each row with end of line
}
html=html+"\\n"; // end of line at the end
document.formstyle.csvBuffer.value=html;
document.formstyle.method='POST';
document.formstyle.action='/template/jsp/csvExport.jsp'; // send it to server which will open this contents in excel file
document.formstyle.target='_blank';
document.formstyle.submit();
// This is the JSP code to output the file in excel
//<%
//
//response.setContentType("application/vnd.ms-excel");
//String buf=request.getParameter("csvBuffer");
//try{response.getWriter().println(buf);}catch(Exception e){}
//%>
}
02:16
Moderators
30/10/2007
Hello,
Thank you for shering the code with the community.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
16:29
24/06/2009
Thanks for sharing the code. It works. But only the data in current grid was captured using the following method
"mya=jQuery(”#list2″).getDataIDs(); // Get All IDs"
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?
Thanks.
Betty
02:57
07/10/2014
Hi betty,
             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 ...
I am using
var jqgridRowIDs = $(tableCtrl).getDataIDs(); // Fetch the RowIDs for this grid
 var allJQGridData = $(tableCtrl).jqGrid('getRowData');
 var headerData = $(tableCtrl).getRowData(jqgridRowIDs[0]);
Â
Plz help me out.....
15:56
Moderators
30/10/2007
Hello,
Â
It is difficult.
If you use server side sorting and data, this should happen, sincxe the grid has only the needed portion.
If you use local data you can use the grid data parameter to get all the data.
Â
var allJQGridData = $(tableCtrl).jqGrid('getGridParam','data');
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Hi Betty,
I created my grids a few years ago and there wasn't away to dump everything to excel.
All of my pages use a Cold Fusion cfc function on the server end. Before I return the data I set a session variable to the value of the query data.
here's and example: I have a function that returns different types of sales orders (phone orders, shipped, not shipped)
  <!--- Save for Export --->
    <cfswitch expression="#Arguments.OpenShpd#">
      <cfcase value="O"><cfset session.DumpSO = get_so></cfcase>
      <cfcase value="N"><cfset session.DumpSNS = get_so></cfcase>
      <cfcase value="S"><cfset session.DumpSOS = get_so></cfcase>
    </cfswitch>
Then on my gridpage above my grid I have links  [To PDF]  and [To Excell] options (these icons and words)
When the user clicks one of these links it sends them to a page that recreates the data in the the chosen format.
Because these are links I can pass url parameters using jquery to gather filter data.
Jim
 Â
18:14
07/10/2014
hi tony,
            i didn't understood your answer.
We are using filter tool bar on export to excel;the export to excel code was copied from code project (Mikes).The problem is that we are able to get all the records to excel from grid,when we filter with particular name we get some records like 10 records i need those 10 records to excel ,if we do filter also we are getting all the records to excel not filtered records.
$("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: "cn" }).navButtonAdd(
'#pager', {caption:"Export to Excel",
buttonicon:"ui-icon-disk",
onClickButton:function() {ExportDataToExcel("#list");
},
position:"last"
});
Â
function ExportDataToExcel(tableCtrl) {
ExportJQGridDataToExcel(tableCtrl,"sample.xlsx");
}
Â
function ExportJQGridDataToExcel(tableCtrl, excelFilename) {Â Â
var allJQGridData = $(tableCtrl).jqGrid('getGridParam', 'data');
 // var allJQGridData = $(tableCtrl).jqGrid('getRowData');
 var jqgridRowIDs = $(tableCtrl).getDataIDs(); // Fetch the RowIDs for this grid
 var headerData = $(tableCtrl).getRowData(jqgridRowIDs[0]);
If i comment getgrid param and if i use getrowdata i cna get filtered records but not all ...
i want to satisy both the condiitons how can i acheive this..
14:31
Moderators
30/10/2007
Hello,
Â
I have already answer of your question.
Â
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
44 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66