一、
二、源码
1、java后台代码-------------用于生成一组数据传到前台页面
private JSONObject resultObj; //json-lib.jar包中自带的对象和方法,方便转换成传输的json类型数据
@SuppressWarnings("unchecked")
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
Map map = new HashMap();
ArrayList al = new ArrayList();
for(int i=0;i<50;i++)
{
Map m = new HashMap();
m.put("itemid", String.valueOf(i));
m.put("mction", "a");
al.add(m);
}
map.put("total", 50);
map.put("rows", al);
resultObj=JSONObject.fromObject(map); //将map对象转换成为json对象
return "success";
}
2、jsp页面代码
<body οnlοad="fm()">
<s:debug></s:debug>
<table id="tt" border="1"></table> //放置表格的容器
</body>
3、js代码
$('#tt').datagrid({
url:'msg.action', //url----指向struts中配置的action
title:'demo',
iconCls:'icon-save',
width:600,
height:350,
nowrap: false,
striped: true,
collapsible:true,
sortName: 'code',
sortOrder: 'desc',
remoteSort: false,
idField:'code',
columns:[[ //列field
{field:'ck',checkbox:true},
{field:'mction',title:'mction',width:100},
{field:'itemid',title:'itemid',width:100}
]] ,
pagination:true,
pageSize:20,
pageNumber:1,
rownumbers:true,
toolbar:[{
id:'btnadd',
text:'Add',
iconCls:'icon-add',
handler:function(){
$('#btnsave').linkbutton('enable');
insertRow();
//appendRow("b","555");
//alert('add')
}
},{
id:'btncut',
text:'Cut',
iconCls:'icon-cut',
handler:function(){
$('#btnsave').linkbutton('enable');
alert('cut')
}
},'-',{
id:'btnsave',
text:'Save',
disabled:true,
iconCls:'icon-save',
handler:function(){
$('#btnsave').linkbutton('disable');
alert('save')
}
}],
onClickRow:function(index,row){ //一些事件编写
alert(index+"****"+row.itemid);
}
});
4、struts配置文件------------关键
<package name="json" namespace="/jsp" extends="json-default">
<action name="msg" class="com.struts.action.FindMsg">
<result type="json" >
<param name="root">resultObj</param>
</result>
</action>
</package>
5、文件目录树
6、源码
下载地址:http://download.csdn.net/detail/yixi524/4463584