ExtJS pagingtoolbar的使用

view层:

  this.bbar = [{
         	 xtype: ‘pagingtoolbar‘,
         	 //增加id
         	 id : ‘ptb‘,
             pageSize: 2,
             store: this.store,
             displayInfo: true,
             plugins: new Ext.ux.ProgressBarPager()
         }];

store层

 1 Ext.define(‘Industry_Demo.store.Industry‘, {
 2      extend: ‘Ext.data.Store‘,
 3      /*
 4      fields: [{name: ‘PK_Industry_ID‘,type: ‘int‘},
 5              {name: ‘Industry_Name‘,type : ‘string‘}
 6              ],
 7              */
 8      model : ‘Industry_Demo.model.Industry‘,
 9      pageSize : 2,
10      //非常重要的属性
11      //autoLoad: {start : 0, limit : 2},
12      proxy: {
13           type : ‘ajax‘,
14           enablePaging: true,
15          // url : ‘data/industries.json‘,
16           url : ‘/IndustryAdmin/getIndustries.do‘,
17           reader: {
18              type : ‘json‘,
19              root : ‘industries‘,
20              successProperty: ‘success‘,
21              totalProperty : ‘total‘
22             
23         }
24      }
25      /*
26      data  : [
27                  {PK_Industry_ID:1,Industry_Name:‘aa‘},
28                  {PK_Industry_ID:2,Industry_Name:‘bb‘}
29              ]
30          */    
31  });

controller层

Ext.define(‘Industry_Demo.controller.Industry‘,{
     //必须和文件同名
      extend : ‘Ext.app.Controller‘,
      init : function() {
          // console.log("Hello");
           this.control({
               
                ‘industryList‘ : {
                    itemdblclick: this.editRecord,
                    render : function(myView){
                        myView.getStore().load({params:{start:0,limit:2}});
                    }
                },

后台代码springmvc+mybatis

@RequestMapping(value="/getIndustries",method=RequestMethod.GET)
    public void getIndustries(HttpServletRequest request,HttpServletResponse response){
        String startString = request.getParameter("start");
        String limitString = request.getParameter("limit");
        int start = Integer.valueOf(startString);
        int limit = Integer.valueOf(limitString);
        System.out.println("select controller层");
        System.out.println(start+" "+limit);
        int num = industryService.getIndustriesNum();
        System.out.println(num+" ");
        List<Industry> list = null;
        list =  industryService.getIndustries(start, limit);
        System.out.println("mission completed I am back");
    
        String jsonString = "{success : true,total : ";
        jsonString +=num;
        jsonString +=",industries : [";
        int i = 0;
        if(list.size()>0){
        for(;i <list.size()-1;i++){
            jsonString += "{id : "+ list.get(i).getId() + ",name : ‘"+list.get(i).getName()+"‘},";
        }
        jsonString +="{id :" + list.get(i).getId()+",name : ‘"+list.get(i).getName()+"‘}]}";
        }
        else{
            jsonString = "{success : true,total : ";
            jsonString +=num;
            //jsonString +=",industries ";
            //jsonString +="{}]}";
             jsonString += "}";
        }
        try {
            response.getWriter().write(jsonString);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println("Something not good happen");
            e.printStackTrace();
        }
        
    }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。