Results 1 to 2 of 2

Thread: 请教:grid's Paging problem!?

  1. #1

    Default 请教:grid's Paging problem!?

    hi everyone:
    用英文来描述问题我真的是不懂啦..请大家见量!

    问题是这样的.:

    我用hibernate+stturs+dwr+ext(2.0 rc1) 做的 grid分页

    用的是网上高手写的dwrdataproxy

    /**
    * DWR proxy for the store
    */
    Ext.data.DWRProxy=function(config){
    Ext.data.DWRProxy.superclass.constructor.call(this);
    Ext.apply(this, config || {});
    };

    Ext.extend(Ext.data.DWRProxy,Ext.data.DataProxy,{
    load:function(params,reader,callback,scope,arg){
    document.dwr={params:params,reader:reader,callback:callback,scopecope,arg:arg};
    if(this.params!==undefined&&this.params!==null) {
    this.callback.call(this, this.params, this.loadResponse);
    } else {
    this.callback.call(this, this.loadResponse);
    }
    },
    loadResponse:function(response){
    var dwr=document.dwr;
    delete document.dwr;
    var result;
    try{
    result=dwr.reader.read(response);
    }
    catch(e){
    //this.fireEvent("loadexception",this,dwr,response,e);
    dwr.callback.call(dwr.scope,null,dwr.arg,false);
    return ;
    }
    dwr.callback.call(dwr.scope,result,dwr.arg,true);
    },
    failure:function(errorString, exception){
    console.log("DWR " + exception);
    },
    update:function(params,records){
    }
    });

    Ext.data.ObjectReader=function(meta,recordType){
    Ext.data.ObjectReader.superclass.constructor.call(this,meta,recordType);
    };

    Ext.extend(Ext.data.ObjectReader,Ext.data.DataReader,{
    read:function(response){
    var sid=this.meta?this.meta.id:null;
    var recordType=this.recordType,fields=recordType.prototype.fields;
    var records=[];
    var root=response;
    for(var i=0;i<root.length;i++){
    var obj=root[i];
    var values={};
    var id=obj[sid];
    for(var j=0,jlen=fields.length;j<jlen;j++){
    var f=fields.items[j];
    var k=(f.mapping!==undefined&&f.mapping!==null)?f.mapping:f.name;
    var v=null;
    var idx=k.indexOf(".");
    if(idx == -1) {
    v=obj[k]!==undefined?obj[k]:f.defaultValue;
    } else {
    var k1=k.substr(0, idx);
    var k2=k.substr(idx+1);
    if(obj[k1]==undefined) {
    v=f.defaultValue;
    } else {
    var obj2=obj[k1];
    v=obj2[k2]!==undefined?obj2[k2]:f.defaultValue;
    }
    }
    v=f.convert(v);
    values[f.name]=v;
    }
    var record=new recordType(values,id);
    records[records.length]=record;
    }
    return {
    records : records,
    totalRecords : records.length
    };
    }
    });

    这个是用到分页的js文件中的一些代码
    var ds = new Ext.data.Store({
    proxy : new Ext.data.DWRProxy({callback : homeworkAction.findAll_pagination,params:{start : '0',limit : '5'}}),
    reader: new Ext.data.ObjectReader({id: 'id'},homeworktype),
    remoteSort: false
    });//定义store

    var HomeWorkManageEditorGridPanel = new Ext.grid.EditorGridPanel({
    store: ds,
    cm: colModel,
    //selModel: new Ext.grid.RowSelectionModel(),
    sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
    loadMask :true,
    autoSizeColumns: true,
    enableColLock:false,
    buttonAlign:'top',
    tbar:
    [{
    iconCls: 'add',
    text: '新增',
    handler :doAdd
    },{
    iconCls: 'remove',
    text: '删除',
    //handler : doDel
    },collegesortComboBox
    ],
    bbar:new Ext.PagingToolbar({
    pageSize: 5,
    store: ds,
    displayInfo: true,
    })
    });

    ds.load();

    这个是前台js

    后台:
    public List<Homework> findAll_pagination(Map paginationform)
    {
    PaginationMapform paginationMapform = new PaginationMapform();
    List<Homework> result= null;
    try
    {
    BeanUtils.populate(paginationMapform, paginationform);

    int start = Integer.parseInt(paginationMapform.getStart());
    int limit = Integer.parseInt(paginationMapform.getLimit());

    result = this.ihomeworkservice.findAll_pagination(start, limit);
    }
    catch (IllegalAccessException e1)
    {
    e1.printStackTrace();
    }
    catch (InvocationTargetException e1)
    {
    e1.printStackTrace();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }


    return result;
    }

    这样..当运行的时候.只会得五条记录.

    按paging时是不能到通过PagingToolbar去改变传到后台的参数的

    PagingToolbar中的记录总数也只会是5,这个数字只是第一分页的大小...不是全部记录的总数,

    PagingToolbar只读取了第一个分页的总数,

    请问..这个要点样改啊!!

    是不是要扩展PagingToolbar..

    事关PagingToolbar好像只能做httprequest的分页,,用dwr做.是传一个map{starttart,limit:limit}类型

    到后台的..

    请指教.

  2. #2
    Ext User yueritian's Avatar
    Join Date
    Dec 2007
    Location
    BeiJing/TianJin China
    Posts
    12

    Default

    首先我用的是ext自带的分页,好使
    就是按页数从后台读取数据过来,这个没研究过
    PHP Code:
    grid = new Ext.grid.GridPanel({
       
    id:'button-grid',
       
    border:false,
       
    bodyBorder:false,
             
    loadMask: {msg:'加载稿件...'},
       
    storestore,
       
    cm: new Ext.grid.ColumnModel([
        new 
    Ext.grid.RowNumberer(),
        
    assetBox,
        
    expander,
        {
    header"创建者"width400,sortabletruedataIndex'creator'},
        {
    header"创建日期"width400,sortabletruedataIndex'createDate'}

       ]),        
       
    smassetBox,
       
    viewConfig: {
                 
    forceFit:true,
                 
    enableRowBody:true,
                 
    showPreview:true
             
    },
       
    pluginsexpander,
       
    //width:578,
       //height:388,
       //frame:true,
       //iconCls:'icon-grid',
       
    renderTo'center',
       
    bbar: new Ext.PagingToolbar({
        
    pageSize15,
        
    storestore,
        
    paramNames : {start'start'limit'limit',cid'cid'},   <<=====&#38656;要注意 这个PagingToolbar控件 参数就只有start和limit 得扩展好象
        
    displayInfotrue,
        
    displayMsg'本页显示 {0} - {1} 总共 {2}',
        
    emptyMsg"没有标题"
       
    })
      });
     
    store = new Ext.data.Store({
       
    url'Asset!takeAssets.action',
       
    baseParams :'cid',
       
    reader: new Ext.data.JsonReader({
        
    root'bean',
        
    id'id',
        
    totalProperty'totalCount'
       
    },[
        {
    name'id'mapping'id'},
        {
    name'title'mapping'title'},
        {
    name'creator'mapping'creator'},
        {
    name'writer'mapping'writer'},
        {
    name'createDate'mapping'createDate'},
        {
    name'publishDate'mapping'publishDate'},
        {
    name'description'mapping'description'},
        {
    name'cid'mapping'cid'},
        {
    name'thumbnail'mapping'thumbnail'},
        {
    name'ispublish'mapping:'ispublish'}
       ]),
       
    remoteSorttrue
      
    });
    store.load({params:{start:0limit:15cid:0}}); 
    这样就Ok了,
    One world, One dream!
    Welcom to China, Welcom to Beijing!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •