2013-03-15 47 views
1

我的应用程序中的分页工具栏有问题。我的商店由PHP脚本填充,该脚本将MySQL数据库表转换为JSON数据。覆盖下一个和上一个按钮分页工具栏sencha extjs 4.1

在我的窗口中,我有一个窗体用于过滤网格的面板。所有“过滤器”作为参数在store.load()调用中传递,PHP脚本完成查询并返回数据。

我的问题是,当我有一些过滤器和我点击页面的下一个按钮工具栏我的过滤器消失,无店外params为加载。如何在nextPage()/ prevPage()调用中发送额外的参数?

编辑: 我解决了使用store.on('beforeload'),这里是我的解决方案:

store.on('beforeload', function(store, operation, opts){ 
    operation.params={ 
     // yuor params here 
     param1: param1Value, 
     param2: param2Value 
    }; 
}, this); 

回答

0

你需要重写MOVENEXT和寻呼工具栏的movePrevious方法,在这些方法中,你可以通过它包含所有自订参数的对象,你需要传递给PHP

/** 
* Move to the next page, has the same effect as clicking the 'next' button. 
*/ 
moveNext : function(){ 
    var me = this, 
     total = me.getPageData().pageCount, 
     next = me.store.currentPage + 1; 

    if (next <= total) { 
     if (me.fireEvent('beforechange', me, next) !== false) { 
      me.store.nextPage({ 
       // all the custom params should go here 
       param1 : 'value1' 
      }); 
     } 
    } 
} 

这将很容易解决您当前的问题,但如果你想有一个通用的解决了在商店将提供这些自订参数每次当上一页/下一页,ST公司获取矿石,那么你可以重写loadPage方法,并添加有自订参数

loadPage: function(page, options) { 
    var me = this; 

    me.currentPage = page; 

    // add your custom params 
    options = Ext.apply({ 
     param1 : 'value1' 
    }, options); 

    // Copy options into a new object so as not to mutate passed in objects 
    options = Ext.apply({ 
     page: page, 
     start: (page - 1) * me.pageSize, 
     limit: me.pageSize, 
     addRecords: !me.clearOnPageLoad 
    }, options); 

    if (me.buffered) { 
     return me.loadToPrefetch(options); 
    } 
    me.read(options); 
} 

参考:

http://docs.sencha.com/ext-js/4-1/source/Paging.html#Ext-toolbar-Paging

http://docs.sencha.com/ext-js/4-1/source/Store.html#Ext-data-Store-method-nextPage

+0

不行的,我使用的参数来尝试这种解决方案,当我点击下一步店没有参数重新加载。我在上面的问题中发布了我的代码 – andyts93 2013-03-18 08:13:27

0

我不知道,如果你发现你的答案,但我有同样的问题这是我发现的。

希望它有帮助。

当您使用参数调用,它只是一个时间。在以前的版本Sencha告诉使用baseParams,但我无法找到它在新的。所以我用代理的extraParams这样:

这是表单按钮,我用它来过滤我的数据

text: 'Filter', 
handler: function() { 
     /* 
     get the form 
     get a record object and set its data 
     */ 
     var form = this.up('form').getForm(); 
     var record = form.getRecord(); 
     form.updateRecord(record); 

     for(name in record.data){ 
      if (record.data.hasOwnProperty(name)) 
       envelopeStore.setExtraParam(name, record.data[name]); 
     } 
     /* 
     envelopeStore.getProxy().extraParams = record.data; 
     *I have some constant params so I needed to add them in a loop as above 
     *you can simply use this 
     */ 

     envelopeGrid.child('pagingtoolbar').moveFirst(); 
     /* 
     do not load store data. It does not change paging. go to first page instead 
     */ 
    }  
相关问题