2013-03-15 68 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 
     */ 
    }