Forum


11:57

10/05/2010

hiii.....
i'm a newbie..
i want export my grid to excel...
my jqgrid configuration is like that..
jQuery('#tableGrid').jqGrid({
//url:'../admspanel/maingridrptcustcomplain.php',
datatype: "xml",
height: 470,
width:680,
mtype:"POST",
colNames:['Code','Date','Username','Customer Name','Contact Person','Menu','Description'],
colModel:[
{name:'code',index:'KdComplain',width:80,align:"left"},
{name:'dateComp',index:'TglInput',width:80,align:"left",formatter:'date',formatoptions: {srcformat:'Y-m-d',newformat:'M d,Y'}},
{name:'username',index:'Username',width:120,align:"left"},
{name:'custName',index:'CustomerName',width:200,align:"left"},
{name:'contact',index:'ContactPerson',width:150,align:"left"},
{name:'menu',index:'Menu',width:180,align:"left"},
{name:'desc',index:'Description',width:350,align:"left"}
],
rowNum:100,
//rowList:[10,20,30],
pager: '#navGrid',
sortname: 'KdComplain',
shrinkToFit:false,
viewrecords: true,
sortorder: "asc",
reloadGrid:false,
//rownumbers:true,
//rownumWidth: 40,
//gridview: true,
scroll: 1,
reloadGrid:false,
caption: "Report Customer Complaint"
});
i have a function that convert that grid to excel
here is my function :
function PrintExcel(DateFrom,DateTo,User) {
//var data = new Array();
var count = $("#tableGrid").jqGrid('getGridParam','records');
var caption = $("#tableGrid").jqGrid('getGridParam','caption');
var colnames = $("#tableGrid").jqGrid('getGridParam','colNames');
var colmodel = $("#tableGrid").jqGrid('getGridParam','colModel');
var ids = $("#tableGrid").getDataIDs();
codeComp = "";
dateComp = "";
usergrid = "";
cust = "";
contact = "";
menu = "";
desc = "";
headernames = "";
headerwidth = "";
for (var i = 0; i < colnames.length; i++) {
headernames = headernames+"|"+colnames[i];
}
for (var i = 0; i < colmodel.length; i++) {
headerwidth = headerwidth+"|"+(colmodel[i].width/10+3);
}
if(count == 0) return false;
for (var i = 0; i < ids.length; i++) {
codeComp = codeComp+"|"+$("#tableGrid").getCell(ids[i],'code');
dateComp = dateComp+"|"+$("#tableGrid").getCell(ids[i],'dateComp');
usergrid = usergrid+"|"+$("#tableGrid").getCell(ids[i],'username');
cust = cust+"|"+$("#tableGrid").getCell(ids[i],'custName');
contact = contact+"|"+$("#tableGrid").getCell(ids[i],'contact');
menu = menu+"|"+$("#tableGrid").getCell(ids[i],'menu');
desc = desc+"|"+$("#tableGrid").getCell(ids[i],'desc');
}
codeComp = codeComp.substring(1);
dateComp = dateComp.substring(1);
usergrid = usergrid.substring(1);
cust = cust.substring(1);
contact = contact.substring(1);
menu = menu.substring(1);
desc = desc.substring(1);
headernames = headernames.substring(1);
headerwidth = headerwidth.substring(1);
window.location = 'doPrintExcel-rptcustcomplain.php?cap='+caption+'&cou='+count+'&hn='+headernames+'&hw='+headerwidth+'&cc='+codeComp+'&dc='+dateComp+'&ug='+usergrid+'&cs='+cust+'&ct='+contact+'&mn='+menu+'&de='+desc+'&f='+DateFrom+'&t='+DateTo+'&u='+User;
}
when i click the Print button, i call PrintToExcel function like that
PrintExcel($('#txtDateFrom').val(),$('#txtDateTo').val(),$('#cboUser :selected').text());
on doPrintExcel-rptcustcomplain.php, i'm split my variabel to array..
and then i print all my variabel to excel
i know is not a good way..
it's work for a small data..
if a grid have a big data, it's work not good because the url that i passing is to long
is there any best way convert to excel?
Best Regards,
zenixgrace
22:49

27/05/2010

Hi,
I have written a few pages with a pear php package that does just that: create an excel document and send it back to the browser. The browser then automatically opens excel.
I am not sure if this fits what you need, but here you go:
http://pear.php.net/package/Sp.....redirected
Best wishes.
07:27

10/05/2010

thanks for ur reply DroidDr...
i mean what the best way to passing my variabel to doPrintExcel-rptcustcomplain.php without use get method (passing the variabel use that URL)
if i use this way, it's only work with a small data..
then if the data is big, it not work because the URL i pass is too long..
i don't know why the browser cut my URL if my URL is to long..
i mean any the other best way for passing my variabel to my doPrintExcel-rptcustcomplain page?
best regards,
zenixgrace
Most Users Ever Online: 715
Currently Online:
26 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