開發環境:
IDE:MyEclipse6.6GA
Web Server:Tomcat 6.0.20
Database:MySql 5.1.36
MVC:Struts2.1.8
FrameWork:Spring2.0,Hibernate3.2
Client UI:Ext2.3.0
一、建立grid頁面(grid2.jsp):
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'combox.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="css/onReady.css">
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script type="text/javascript" src="extjs/ext-lang-zh_TW.js"></script>
<script type="text/javascript">
<!--
Ext.onReady(function(){
var store = new Ext.data.Store({
url: 'html/grid0.xml',
reader: new Ext.data.XmlReader({record:'row',id:'id'}, [
'id',
'coverthumb',
'title',
'director',
{name: 'released', type: 'date', dateFormat: 'Y-m-d'},
'genre',
'tagline',
{name: 'price', type: 'float'},
{name: 'available', type: 'bool'}
])
});
store.load();
//Combining two columns function
function title_tagline(val, x, store){
return '<b>'+val+'</b><br>'+store.data.tagline;
}
//Generating HTML and graphics
function cover_image(val){
return '<img src="images/'+val+'.jpg" width="50%" height="50%">';
}
// add your data store here
var grid = new Ext.grid.GridPanel({
//renderTo: document.body,
renderTo:'example-grid',
frame:true,
title: 'Movie Database',
height:200,
width:550,
stripeRows:true,
store: store,
//Defining a Grids column model and want to display column
columns: [
{header: "Cover", dataIndex: 'coverthumb',renderer:cover_image},
//Combining two columns
{header: "Title", dataIndex: 'title',renderer:title_tagline},
{header: "Director", dataIndex: 'director'},
//Client-side sorting
{header: "Released", dataIndex: 'released',sortable:true,
renderer: Ext.util.Format.dateRenderer('m/d/Y')},
{header: "Genre", dataIndex: 'genre'},
{header: "Price",dataIndex: 'price'},
//setup hidden column
{header: "Tagline", dataIndex: 'tagline',hidden:true}
]
});
});
//-->
</script>
</head>
<body><br>
<center>
<h3><font color="red">Movie Database Grid</font></h3><br>
</center>
<table align="center" border="0">
<tr>
<td>
<div id="example-grid"></div>
<td>
</tr>
</table>
</body>
</html>
二、Server side xml file(grid0.xml):
<?xml version="1.0" encoding="UTF-8"?> <dataset> <row> <id>1</id> <title>Office Space</title> <director>Mike Judge(喬治麥克)</director> <released>1999-02-19</released> <genre>1</genre> <tagline>Work Sucks</tagline> <coverthumb>OfficeSpace</coverthumb> <price>19.95</price> <active>1</active> </row> <row> <id>3</id> <title>Super Troopers</title> <director>Jay Chandrasekhar</director> <released>2002-02-15</released> <genre>1</genre> <tagline>Altered State Police</tagline> <coverthumb>SuperTroopers</coverthumb> <price>14.95</price> <active>1</active> </row> //...more rows of data removed for readability...// </dataset>
三、測試結果:
1.http://localhost:8080/ExtStudy/Basic/grid2.jsp
沒有留言:
張貼留言