日期:2014-05-20 浏览次数:22361 次
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" type="text/css" href="css/flexigrid/flexigrid.css"> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/flexigrid.js"></script> <title>FlexiGrid_Strut</title> </head> <body> <table id="flex1" style="display:none"></table> <script type="text/javascript"> $("#flex1").flexigrid ( { url: 'book.action', dataType: 'json', colModel : [ { display:'作者', name:'author', width:100, align:'center' }, { display:'名称', name:'name', width:150, align:'center' } ], searchitems : [ {display: '作者', name : 'author'}, {display: 'Name', name : 'name', isdefault: true} ], buttons:[ { name:'添加',bclass:'add',onpress:test}, { name:'删除',bclass:'delete',onpress:test}, { name:'修改',bclass:'modify',onpress:test}, { separator:true} ], usepager: true, //是否分页 title: '图书', procmsg:'正在处理数据,请等待...', rpOptions: [8,10], //可选择设定的每页结果数 useRp: true, //是否使用分面 rp: 8, showTableToggleBtn: true, width: '500', height: 200, nomsg:'不存在记录!', pagestat:'显示{from}至{to} 条 共{total}条', errormsg:'连接失败,请重试', showToggleBtn:false, autoload:true //不允许自动加载 } ); </script> </body> </html>
<?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> <package name="book" extends="json-default"> <action name="book" class="flexigrid.Action" > <result type="json"/> </action> </package> </struts>
package flexigrid; import java.util.ArrayList; import java.util.List; import org.apache.struts2.json.annotations.JSON; import com.opensymphony.xwork2.ActionSupport; public class Action extends ActionSupport{ private Integer page; //第几页 private Integer total; //共几页 private Integer rp; //每页显示 private List<Book> rows; //set和get @JSON(name="page") public Integer getPage() { return page; } public void setPage(Integer page) { this.page = page; } @JSON(name="total") public Integer getTotal() { return total; } public void setTotal(Integer total) { this.total = total; } @JSON(name="rp") public Integer getRp() { return rp; } public void setRp(Integer rp) { this.rp = rp; } @JSON(name="rows") public List<Book> getRows() { return rows; } public void setRows(List<Book> rows) { this.rows = rows; } @Override public String execute()throws Exception{ total = 2; rows = new ArrayList<Book>(); Book book1 = new Book(); book1.setId(2); book1.setAuthor("TOM"); book1.setName("Java"); Book book2 = new Book(); book2.setId(3); book2.setAuthor("JIM"); book2.setName(".NET"); rows.add(book1); rows.add(book2); return SUCCESS; } }