Abiram
26 Sep 2012, 10:10 PM
Hi iam new to extjs can any one help me to do excel export from grid view
the code i use is here
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@page import = "java.sql.*"%>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="ext/examples/shared/example.css" />
<link rel ="stylesheet" type ="text/css" href="ext/style.css"
<script type="text/javascript" src ="ext/ext-all.js"></script>
<script type ="text/javascript" src ="ext/bootstrap.js"></script>
<script type ="text/javascript" src ="ext-base.js"></script>
<script type="text/javascript" src ="ext/ext.js"></script>
<script type="text/javascript" src ="ext/ext-dev.js"></script>
<script type="text/javascript" src ="ext/ext-all-dev.js"></script>
<script type ="text/javascript" src ="ext/ux/exporter/Exporter-all.js"></script>
<script type="text/javascript"src="../ux/exporter/Exporter.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor ="lightblue" background ="background1.jpg">
<form name="form1">
<table border="1">
<thead>
<tr>
<td>
<a href ="PatientPagingView.jsp" target="_top"><font size ="5" color ="white"><u>To View Patient Details </u></font></a></td>
<td><a href ="EmployeePagingView.jsp"><font size ="5" color ="white"><u>To View Employee Details </u></font></a></td>
<td><a href ="../index.jsp"><font size ="5" color ="white"><u>To Logout </u></font></a>
</td>
</tr>
</thead>
</table>
<table border="1">
<tbody>
<tr>
<td>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos", "root", "ims");
Statement stmt = con.createStatement();
String query = "select PatientID,PatientName,BloodGroup,Treament,Status,Consultant from patient";
ResultSet rs = stmt.executeQuery(query);
int i;
String gridData = "";
rs.last();
int numrows = rs.getRow();
rs.first();
rs.beforeFirst();
for (i = 0; i <= numrows; i++) {
while (rs.next()) {
if (gridData.equals("")) {
gridData = "['" + rs.getString(1) + "','" + rs.getString(2) + "','" + rs.getString(3) + "','" + rs.getString(4) + "','" + rs.getString(5) + "','" + rs.getString(6) + "']";
} else {
gridData += ",['" + rs.getString(1) + "','" + rs.getString(2) + "','" + rs.getString(3) + "','" + rs.getString(4) + "','" + rs.getString(5) + "','" + rs.getString(6) + "']";
}
}
}
session.setAttribute("user","Abi");
String test ="ram";
session.setAttribute("user1",test);
String ExcelSession = "user1";
rs.close();%>
<div id="PatientInfo" style='width:100%;display:block'></div>
<script type="text/javascript" >
Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.ux', 'ext/examples/ux');
Ext.Loader.setPath('Ext.ux.exporter','../ux/exporter');
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.form.*',
'Ext.state.*',
'Ext.ux.exporter.Exporter.*',
'Ext.ux.exporter.excelFormatter.*',
'Ext.ux.exporter.csvFormatter.*',
'Ext.ux.exporter.Button.*'
]);
var checkval;
var PatientData = [ <%= gridData%> ];
var PatientInfo = Ext.create('Ext.data.ArrayStore', {
fields: [
{name:'resource1'},
{name:'resource2'},
{name:'resource3'},
{name:'resource4'},
{name:'resource5'},
{name:'resource6'},
],
data: PatientData
});
Ext.onReady(function()
{
var exportButton = Ext.create('Ext.button.Button',{
text:"Download as.xls",
handler:function(button){
var gridPanel=button.up('gridpanel');
var dataURL='data:application/vnd.ms-excel;base64,'+Ext.ux.exporter.Exporter.exportGrid(gridPanel);
window.location.href=dataURL;
}
})
function reCheck(value, p, record){
return Ext.String.format(
'<input type="checkbox" id="check" name="check" value="{0}"/>',
record.data.resource1);
}
function buttoncheck()
{
return Ext.String.format('<input type ="button" id = "b1" name = "Edit" value = "Edit" onclick = "checke"/>');
}
var grid = Ext.create('Ext.grid.GridPanel', {
store: PatientInfo,
renderTo : 'PatientInfo',
width:screen.width-480,
title:'PatientInformation',
height:405,
columns:[
{
header: 'CheckValue',
dataIndex: 'resource1',
width:80,
renderer: reCheck,
align: 'center',
hideable: false,
sortable: false
},
{
text:'PatientName',
width:100,
sortable:true,
dataIndex:'resource2'
},
{
text:'BloodGroup',
width:70,
sortable:true,
dataIndex:'resource3'
},
{
text:'Type Of Treatment',
width:100,
sortable:true,
dataIndex:'resource4'
},
{
text:'Status',
width:100,
sortable:true,
dataIndex:'resource5'
},
{
text:'Consultant',
width:100,
sortable:true,
dataIndex:'resource6'
}
],
columnLines: true,
viewConfig: {
stripeRows: true,
trackOver: true
},
dockedItems:
[{
xtype: 'pagingtoolbar',
store: PatientInfo,
dock: 'bottom',
displayInfo:true
},
{
buttons: [
{
text: 'INSERT',
iconAlign:'center',
handler: function(){
location.href="PatientDetails.html";
}
},
{
text: 'UPDATE',
iconAlign:'center',
handler:function() {
var e= document.form1.check.length;
var cnt=0;
for(cnt=0;cnt<e;cnt++) {
if(document.form1.check[cnt].checked==true){
checkval = document.getElementsByName("check")[cnt].value;
alert(checkval);
location.href = "PatientUpdate.jsp?PatientID="+checkval;
}
}
}
},
{
text:'DELETE',
iconAlign:'center',
handler: function(){
return '<input type="button" value="Delete" onclick = "retransfer()"/>';
}
},
{
text:'Excel',
handler:function(){
location.href = "sample3.jsp";
}
},exportButton
/* {id:'grid-excel-button',
text:'Export to excel',
handler:function(){
document.location = 'data:application/vnd.ms-excel;base64,'+Base64.encode(grid.getExcelXml());
}
}*/
]
}],
tbar:[{
alias:'widget.exportbutton',
store:PatientInfo
}]
});
});
</script>
<%
} catch (Exception e) {
out.print(e);
}
%>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
The error i got at the time of button click on the web console. The error is Ext.ux.exporter is undefined source
Please hepl me
the code i use is here
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@page import = "java.sql.*"%>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="ext/examples/shared/example.css" />
<link rel ="stylesheet" type ="text/css" href="ext/style.css"
<script type="text/javascript" src ="ext/ext-all.js"></script>
<script type ="text/javascript" src ="ext/bootstrap.js"></script>
<script type ="text/javascript" src ="ext-base.js"></script>
<script type="text/javascript" src ="ext/ext.js"></script>
<script type="text/javascript" src ="ext/ext-dev.js"></script>
<script type="text/javascript" src ="ext/ext-all-dev.js"></script>
<script type ="text/javascript" src ="ext/ux/exporter/Exporter-all.js"></script>
<script type="text/javascript"src="../ux/exporter/Exporter.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor ="lightblue" background ="background1.jpg">
<form name="form1">
<table border="1">
<thead>
<tr>
<td>
<a href ="PatientPagingView.jsp" target="_top"><font size ="5" color ="white"><u>To View Patient Details </u></font></a></td>
<td><a href ="EmployeePagingView.jsp"><font size ="5" color ="white"><u>To View Employee Details </u></font></a></td>
<td><a href ="../index.jsp"><font size ="5" color ="white"><u>To Logout </u></font></a>
</td>
</tr>
</thead>
</table>
<table border="1">
<tbody>
<tr>
<td>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos", "root", "ims");
Statement stmt = con.createStatement();
String query = "select PatientID,PatientName,BloodGroup,Treament,Status,Consultant from patient";
ResultSet rs = stmt.executeQuery(query);
int i;
String gridData = "";
rs.last();
int numrows = rs.getRow();
rs.first();
rs.beforeFirst();
for (i = 0; i <= numrows; i++) {
while (rs.next()) {
if (gridData.equals("")) {
gridData = "['" + rs.getString(1) + "','" + rs.getString(2) + "','" + rs.getString(3) + "','" + rs.getString(4) + "','" + rs.getString(5) + "','" + rs.getString(6) + "']";
} else {
gridData += ",['" + rs.getString(1) + "','" + rs.getString(2) + "','" + rs.getString(3) + "','" + rs.getString(4) + "','" + rs.getString(5) + "','" + rs.getString(6) + "']";
}
}
}
session.setAttribute("user","Abi");
String test ="ram";
session.setAttribute("user1",test);
String ExcelSession = "user1";
rs.close();%>
<div id="PatientInfo" style='width:100%;display:block'></div>
<script type="text/javascript" >
Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.ux', 'ext/examples/ux');
Ext.Loader.setPath('Ext.ux.exporter','../ux/exporter');
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.form.*',
'Ext.state.*',
'Ext.ux.exporter.Exporter.*',
'Ext.ux.exporter.excelFormatter.*',
'Ext.ux.exporter.csvFormatter.*',
'Ext.ux.exporter.Button.*'
]);
var checkval;
var PatientData = [ <%= gridData%> ];
var PatientInfo = Ext.create('Ext.data.ArrayStore', {
fields: [
{name:'resource1'},
{name:'resource2'},
{name:'resource3'},
{name:'resource4'},
{name:'resource5'},
{name:'resource6'},
],
data: PatientData
});
Ext.onReady(function()
{
var exportButton = Ext.create('Ext.button.Button',{
text:"Download as.xls",
handler:function(button){
var gridPanel=button.up('gridpanel');
var dataURL='data:application/vnd.ms-excel;base64,'+Ext.ux.exporter.Exporter.exportGrid(gridPanel);
window.location.href=dataURL;
}
})
function reCheck(value, p, record){
return Ext.String.format(
'<input type="checkbox" id="check" name="check" value="{0}"/>',
record.data.resource1);
}
function buttoncheck()
{
return Ext.String.format('<input type ="button" id = "b1" name = "Edit" value = "Edit" onclick = "checke"/>');
}
var grid = Ext.create('Ext.grid.GridPanel', {
store: PatientInfo,
renderTo : 'PatientInfo',
width:screen.width-480,
title:'PatientInformation',
height:405,
columns:[
{
header: 'CheckValue',
dataIndex: 'resource1',
width:80,
renderer: reCheck,
align: 'center',
hideable: false,
sortable: false
},
{
text:'PatientName',
width:100,
sortable:true,
dataIndex:'resource2'
},
{
text:'BloodGroup',
width:70,
sortable:true,
dataIndex:'resource3'
},
{
text:'Type Of Treatment',
width:100,
sortable:true,
dataIndex:'resource4'
},
{
text:'Status',
width:100,
sortable:true,
dataIndex:'resource5'
},
{
text:'Consultant',
width:100,
sortable:true,
dataIndex:'resource6'
}
],
columnLines: true,
viewConfig: {
stripeRows: true,
trackOver: true
},
dockedItems:
[{
xtype: 'pagingtoolbar',
store: PatientInfo,
dock: 'bottom',
displayInfo:true
},
{
buttons: [
{
text: 'INSERT',
iconAlign:'center',
handler: function(){
location.href="PatientDetails.html";
}
},
{
text: 'UPDATE',
iconAlign:'center',
handler:function() {
var e= document.form1.check.length;
var cnt=0;
for(cnt=0;cnt<e;cnt++) {
if(document.form1.check[cnt].checked==true){
checkval = document.getElementsByName("check")[cnt].value;
alert(checkval);
location.href = "PatientUpdate.jsp?PatientID="+checkval;
}
}
}
},
{
text:'DELETE',
iconAlign:'center',
handler: function(){
return '<input type="button" value="Delete" onclick = "retransfer()"/>';
}
},
{
text:'Excel',
handler:function(){
location.href = "sample3.jsp";
}
},exportButton
/* {id:'grid-excel-button',
text:'Export to excel',
handler:function(){
document.location = 'data:application/vnd.ms-excel;base64,'+Base64.encode(grid.getExcelXml());
}
}*/
]
}],
tbar:[{
alias:'widget.exportbutton',
store:PatientInfo
}]
});
});
</script>
<%
} catch (Exception e) {
out.print(e);
}
%>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
The error i got at the time of button click on the web console. The error is Ext.ux.exporter is undefined source
Please hepl me