ExtJs 實(shí)現(xiàn)動(dòng)態(tài)加載grid完整示例
Ext3.3中文文檔
數(shù)據(jù)表的結(jié)構(gòu)是:數(shù)據(jù)表table > 記錄record > 字段
store的結(jié)構(gòu)是: Ext.data.Store > Ext.data.Record>Ext.dataDataField
store 首先驅(qū)動(dòng) DataProxy 加載數(shù)據(jù) ,DataProxy加載完成會(huì)驅(qū)動(dòng) DataReader時(shí)行解析,最終獲得Record對(duì)象。
1.bean :
package com.leo.bean;
public class Person {
private String name;
private int age;
private String sex;
private String birthday;
public Person(String name, int age, String sex, String birthday) {
super();
this.name = name;
this.age = age;
this.sex = sex;
this.birthday = birthday;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
}
2.action
package com.leo.action;
import java.util.ArrayList;
import java.util.List;
import com.leo.bean.Person;
import com.opensymphony.xwork2.ActionSupport;
public class ExtjsAction extends ActionSupport {
private long results;
private List items;
public long getResults() {
return results;
}
public void setResults(long results) {
this.results = results;
}
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
}
public String execute() throws Exception {
this.results = 3;
Person p1 = new Person("張三", 29, "男", "1990-10-22");
Person p2 = new Person("李四", 28, "男", "1991-03-30");
Person p3 = new Person("王五", 27, "女", "1993-08-17");
this.items = new ArrayList<Person>();
this.items.add(p1);
this.items.add(p2);
this.items.add(p3);
return SUCCESS;
}
}
3.struts-xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<include file="struts-default.xml" />
<package name="/json" namespace="/" extends="json-default">
<action name="extjsaction" class="com.leo.action.ExtjsAction">
<result type="json">
</result>
</action>
</package>
</struts>
4.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
</web-app>
5.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ExtJs與Struts2結(jié)合</title>
<link rel="stylesheet" href="ext-3.1.1/resources/css/ext-all.css" type="text/css"></link>
<script type="text/javascript" src="ext-3.1.1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-3.1.1/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
var store = new Ext.data.JsonStore({
url:'json/extjsaction.action',//返回的是DataProxy對(duì)象
root:'items',
fields:['name','age','sex','birthday']
});
store.load();
var grid = new Ext.grid.GridPanel({
store:store,
viewConifg:{
forceFit:true
},
columns:[
{header:'姓名',dataIndex:'name'},
{header:'年齡',dataIndex:'age'},
{header:'性別',dataIndex:'sex'},
{header:'生日',dataIndex:'birthday'}
]
});
var win = new Ext.Window({
title:'store ',
width:600,
height:400,
layout:'fit',//這個(gè)是布局
items:grid
});
win.show();
});
</script>
</head>
<body>
</body>
</html>
圖示:

相關(guān)文章
一個(gè)簡(jiǎn)單的Ext.XTemplate的實(shí)例代碼
把省份與城市以樹(shù)的形式輸出的Ext.XTemplate的實(shí)例代碼,需要的朋友可以參考下2012-03-03Ajax請(qǐng)求在數(shù)據(jù)量大的時(shí)候出現(xiàn)超時(shí)的解決方法
這篇文章主要介紹了Ajax請(qǐng)求在數(shù)據(jù)量大的時(shí)候出現(xiàn)超時(shí)的解決方法,需要的朋友可以參考下2014-02-02Extjs grid panel自帶滾動(dòng)條失效的解決方法
對(duì)gridPanel中的stroe數(shù)據(jù)進(jìn)行過(guò)濾,所以有時(shí)候總是導(dǎo)致gridPanel自身所帶的scrollbar失效,好了,現(xiàn)在來(lái)說(shuō)說(shuō)怎么解決scrollbar失效2014-09-09extjs 分頁(yè)使用jsp傳遞數(shù)據(jù)示例
extjs實(shí)現(xiàn)的分頁(yè),使用jsp傳遞數(shù)據(jù),具體實(shí)現(xiàn)過(guò)程如下,需要的朋友莫錯(cuò)過(guò)2014-07-07Ext JS 4實(shí)現(xiàn)帶week(星期)的日期選擇控件(實(shí)戰(zhàn)一)
有一些日期選擇的需求是要看到星期,就是日期中的哪一天是這一年的第幾周,遺憾的是Ext js 并沒(méi)有提供這樣的配置,下面為大家分享下理想的解決方法2013-08-08ExtJS如何設(shè)置與獲取radio控件的選取狀態(tài)
radio控件的選取狀態(tài)如何設(shè)置與獲取,下面使用ExtJS來(lái)簡(jiǎn)單實(shí)現(xiàn)下,感興趣的朋友可以參考下2014-01-01ExtJS 2.0 實(shí)用簡(jiǎn)明教程之布局概述
所謂布局就是指容器組件中子元素的分布、排列組合方式。Ext的所有容器組件都支持而局操作,每一個(gè)容器都會(huì)有一個(gè)對(duì)應(yīng)的布局,布局負(fù)責(zé)管理容器組件中子元素的排列、組合及渲染方式等。2009-04-04extjs 時(shí)間范圍選擇自動(dòng)判斷的實(shí)現(xiàn)代碼
這篇文章主要介紹了extjs 時(shí)間范圍選擇自動(dòng)判斷的實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-06-06ExtJS 2.0實(shí)用簡(jiǎn)明教程 之Ext類庫(kù)簡(jiǎn)介
ExtJS由一系列的類庫(kù)組成,一旦頁(yè)面成功加載了ExtJS庫(kù)后,我們就可以在頁(yè)面中通過(guò)javascript調(diào)用ExtJS的類及控件來(lái)實(shí)現(xiàn)需要的功能。2009-04-04