Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Export jQGrid data to Excel - Solution that worked for me
04/02/2009
12:51
Avatar
seetharaman
Member
Members
Forum Posts: 12
Member Since:
20/06/2008
sp_UserOfflineSmall Offline

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){}
//%>

}

05/02/2009
02:16
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

09/03/2009
13:03
Avatar
Jim P
Member
Members
Forum Posts: 102
Member Since:
29/01/2009
sp_UserOfflineSmall Offline

When I try the code I get the following error:

document.formstyle is undefined

in Firebug.

on this line:

document.formstyle.csvBuffer.value=html;

which is the first one of that type.   I'm not a php coder and just a beginner with js and jqgrid.  Any help would be appreciated.

TIA

Jim

01/09/2009
16:29
Avatar
betty
Member
Members
Forum Posts: 22
Member Since:
24/06/2009
sp_UserOfflineSmall Offline

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

10/10/2014
02:57
Avatar
mcfarland
Member
Members
Forum Posts: 11
Member Since:
07/10/2014
sp_UserOfflineSmall Offline

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.....

21/10/2014
15:56
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

21/10/2014
22:25
Avatar
Jim P
Member
Members
Forum Posts: 102
Member Since:
29/01/2009
sp_UserOfflineSmall Offline

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

  

29/10/2014
18:14
Avatar
mcfarland
Member
Members
Forum Posts: 11
Member Since:
07/10/2014
sp_UserOfflineSmall Offline

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..

30/10/2014
14:31
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information