Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17236
  • 博文数量: 6
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-13 14:29
个人简介

人生若只如初见,当时只道是寻常.

文章分类

全部博文(6)

文章存档

2013年(6)

我的朋友

分类: Java

2013-03-21 20:58:51

datagrid分页 有一个附加的分页控件,只需后台获取分页控件自动提交的两个参数rows每页显示的记录数和page;//当前第几页

然后读取相应页数的记录,和总记录数total一块返回即可 界面如下:

1、下边是datagrid的显示对话框,我直接用table把列头显示出来,感觉比用js写要易于阅读

 
    
 
        
 
            
 
            
 
            
 
            
 
            
 
            
 
            
 
            
 
            
 
           
 
 
    
 
部门 网站 名称 管理员 注释 类型 电话 职务 启用监测 要重级别
 
2、js代码,用于构建datagrid

注意 要想显示分页控件,pagination属性必须为true

?
//datagrid初始化 
    $('#list_data').datagrid({ 
        title:'应用系统列表', 
        iconCls:'icon-edit',//图标 
        width: 700, 
        height: 'auto', 
        nowrap: false, 
        striped: true, 
        border: true, 
        collapsible:false,//是否可折叠的 
        fit: true,//自动大小 
        url:'listApp.action', 
        //sortName: 'code', 
        //sortOrder: 'desc', 
        remoteSort:false,  
        idField:'fldId', 
        singleSelect:false,//是否单选 
        pagination:true,//分页控件 
        rownumbers:true,//行号 
        frozenColumns:[[ 
            {field:'ck',checkbox:true} 
        ]], 
        toolbar: [{ 
            text: '添加', 
            iconCls: 'icon-add', 
            handler: function() { 
                openDialog("add_dialog","add"); 
            } 
        }, '-', { 
            text: '修改', 
            iconCls: 'icon-edit', 
            handler: function() { 
                openDialog("add_dialog","edit"); 
            } 
        }, '-',{ 
            text: '删除', 
            iconCls: 'icon-remove', 
            handler: function(){ 
                delAppInfo(); 
            } 
        }], 
    }); 
    //设置分页控件 
    var p = $('#list_data').datagrid('getPager'); 
    $(p).pagination({ 
        pageSize: 10,//每页显示的记录条数,默认为10 
        pageList: [5,10,15],//可以设置每页记录条数的列表 
        beforePageText: '第',//页数文本框前显示的汉字 
        afterPageText: '页    共 {pages} 页', 
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录', 
        /*onBeforeRefresh:function(){
            $(this).pagination('loading');
            alert('before refresh');
            $(this).pagination('loaded');
        }*/ 
    }); 

3、后台我是通过struts2处理的数据 返回json串

?
private JSONObject result;//返回的json 
       
    private String rows;//每页显示的记录数 
       
    private String page;//当前第几页 
   
        private AppServiceInter appService; 
   
    public JSONObject getResult() { 
        return result; 
    } 
    public void setResult(JSONObject result) { 
        this.result = result; 
    } 
    public void setAppService(AppServiceInter appService) { 
        this.appService = appService; 
    } 
   
        public String getRows() { 
        return rows; 
    } 
    public void setRows(String rows) { 
        this.rows = rows; 
    } 
    public String getPage() { 
        return page; 
    } 
    public void setPage(String page) { 
        this.page = page; 
    } 
        /**
     * 查询应用系统
     * @return
     */ 
    public String listApp() { 
        System.out.println("---------------"); 
        //当前页 
        int intPage = Integer.parseInt((page == null || page == "0") ? "1":page); 
        //每页显示条数 
        int number = Integer.parseInt((rows == null || rows == "0") ? "10":rows); 
        //每页的开始记录  第一页为1  第二页为number +1  
        int start = (intPage-1)*number; 
           
        List list = appService.findByPageApp(start,number);//每页的数据,放入list 
            Map jsonMap = new HashMap();//定义map 
            jsonMap.put("total", appService.getCountApp());//total键 存放总记录数,必须的 
            jsonMap.put("rows", list);//rows键 存放每页记录 list 
            result = JSONObject.fromObject(jsonMap);//格式化result   一定要是JSONObject 
           
        //result = JSONArray.fromObject(jsonMap); 
        return SUCCESS; 
    } 

4、附上struts.xml配置文件

?
 
         
             
                result 
             
         
 

阅读(2264) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~