[code="java"]
/**JS文件*/
Ext.onReady(function(){
/***DataGrid界面****/
var fields = ["id","time","source","destination","protocol","info"];
/*var dataUrl;*/
var proxy = new Ext.data.HttpProxy({
url: 'dataPacket.action',
method: 'POST'
});
var reader = new Ext.data.JsonReader(
{totalProperty :'totalProperty',root:'root'},
fields)
var store = new Ext.data.Store(
{ proxy: proxy, reader: reader }
);
/* var store = new Ext.data.Store({
autoLoad:true,
remoteSort: false,
autoDestroy: true,
listeners: {
render: {
fn: function(){
store.load({
params: {
start: 0,
limit: 5
}
});
}
}
},
proxy:new Ext.data.HttpProxy({url: "dataPacket.action"}),
//proxy: new Ext.data.PagingMemoryProxy(),
reader:new Ext.data.JsonReader({id:"id",time:"time",source:"source",destination:"destination",protocol:"protocol",info:"info",totalProperty :'totalProperty',root:'root'},fields)
});*/
//store.load({params:{start:0,limit:10}});
//var sm = new Ext.grid.CheckboxSelectionModel();
var cm = new Ext.grid.ColumnModel([
{
id:"id",
header:"NO.",
dataIndex:"id",
menuDisabled:true
},{
header:"Time",
dataIndex:"time",
menuDisabled:true
},{
header:"Source",
dataIndex:"source",
menuDisabled:true
},{
header:"Destination",
dataIndex:"destination",
menuDisabled:true
//renderer:formetSex
},{
header:"Protocol",
dataIndex:"protocol",
menuDisabled:true
//sortable:true
},{
header:"Info",
dataIndex:"info",
width:400,
menuDisabled:true
}
]);
var grid = new Ext.grid.GridPanel({
store :store,
title:"解码服务的前端原型",
region:'center',
el:'north-div',
margins: '2 2 2 2',
width:800,
height:300,
cm:cm,
autoExpandColumn: 'id',
loadMask: {msg:'正在加载数据,请稍侯……'},
bbar: new Ext.PagingToolbar({
pageSize: 5,
store: store,
displayInfo: true,
displayMsg: '显示第{0} 条到{1} 条记录,一共{2} 条',
emptyMsg: "没有记录"
})
});
grid.render(Ext.getBody());
store.load({ params: { start: 0, limit: 5} });
grid.addListener('rowclick', rowClickFn);
grid.getSelectionModel().selectFirstRow();
/***添加树界面 ***/
var Tree = Ext.tree;
var tree = new Tree.TreePanel({
region:'south',
el:'south-div',
margins: '2 2 2 2',
useArrows:true,
autoScroll:true,
animate:true,
enableDD:false,//是否可以拖动
//enableDrag:true,
containerScroll: true,
width:800,
height:300,
rootVisible:false,
loader: new Tree.TreeLoader({
dataUrl:'dataDetail.action?number=0'
})
});
var root = new Tree.AsyncTreeNode({
text: 'Ext JS',
draggable:false,
id:'source'
});
tree.setRootNode(root);
root.expand();
function changeDataDetail(number)
{
//alert("aa");
tree.loader = new Tree.TreeLoader({
dataUrl:'dataDetail.action?number='+number
});
tree.root.reload();
}
function rowClickFn(grid, rowIndex, e) {
changeDataDetail(rowIndex);
//alert('你单击了' + rowIndex);
}
grid.addListener('rowcontextmenu', rightClickFn);//右键菜单代码关键部分
var rightClick = new Ext.menu.Menu({
id:'rightClickCont',
items: [
{
//id: 'rMenu1',
//handler: rMenu1Fn,
text: '右键菜单1'
},
{
//id: 'rMenu2',
//handler: rMenu2Fn,
text: '右键菜单2'
}
]
});
function rightClickFn(grid,rowindex,e){
e.preventDefault();
rightClick.showAt(e.getXY());
}
var viewport = new Ext.Viewport({
//region:'north',
layout:'border',
items:[grid,tree]
});
});
[/code]
[code="java"]
/**后台java代码*/
package com.botwave.action;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONArray;
import com.botwave.actionform.DataActionform;
import com.opensymphony.xwork2.ActionSupport;
public class DataPacketAction extends ActionSupport{
private String menuString;//Json数据的字符串形式
private List<DataActionform> xmlDataPacket;//存储数据包信息的数组
public String execute() {
System.out.println("aaa");
XmlData();
return "success";
}
public void XmlData()
{
xmlDataPacket = new ArrayList<DataActionform>();
//DataPacketDao dataPacket = new DataPacketDao();
DataFactory createFactory = new DataFactory();//实例化工厂对象
xmlDataPacket = createFactory.createDataPacket().selectPacketData();//返回IF_DataPacket接口实例并实现接口方法
//DataActionform demoProperty=new DataActionform();//实例化actionform
JSONArray jsonObject = JSONArray.fromObject(xmlDataPacket);//json数据包,通过json返回数据包
try {
/**这里的menuString是返回的到js的数据源,totalProperty的值为11*/
menuString = "{totalProperty:" + (xmlDataPacket.size()) + ",root:" + jsonObject.toString()+ "}";
//demoProperty.setMenuString("{totalProperty:" + (a-1) + ",root:" + jsonObject.toString()+ "}");
} catch (Exception e) {
menuString = "ss";
//demoProperty.setMenuString("ss");
}
//System.out.println( xmlDataTitle.size() );
}
public String getMenuString() {
return menuString;
}
public void setMenuString(String menuString) {
this.menuString = menuString;
}
}
[/code]
问题:在GridPanel里面显示的时候是全部数据都在第一页显示出来,并没有达到分页的效果,图片如下:
[img]http://dl.iteye.com/upload/attachment/284917/43bf3a23-aeb6-3917-bfdd-63c74eb662fb.jpg[/img]