How to clear the store and update a paging toolbar?
Asked Answered
C

11

18

i need to reset paging toolbar parameters as "page", "start", "limit" when i click on a search button to re-load grid store with different parametres!

how can i do it?

the problem is that when i am on the next page, and i do a new search, i have the parameters page=2, start=25, limit=25 dirty, instead i need to reset this parametres.

my code:

listeners: {
    click: function(){
        Ext.getCmp('GrlGio').getStore().removeAll();
        Ext.getCmp('GrlGio').store.load({
                params:{
                  mode: "RIC",
                  DataRicerca: dd,
                  Pit: Ext.getCmp('cmbPiattaforma').getValue()
                }
        });
    }
 }

thanks!

Chichi answered 15/9, 2011 at 15:23 Comment(1)
Thanks for asking this question. I ran into a similar issue, and this post helped!Marolda
L
7

you can manualy reset the params

Ext.getCmp('GrlGio').getStore().getProxy().pageParam =1;
Ext.getCmp('GrlGio').getStore().getProxy().startParam =0;

and then do the store load. I know it looks hardcoded but it's the only solution i found...

Lheureux answered 15/9, 2011 at 15:48 Comment(8)
thanks! this is good for me! but HOW CAN I REFRESH pagingtollbar info??Chichi
with pagingToolbar.moveFirst() i do another request! so in this way, when i click on serarch button, i get 2 once the same store from serverChichi
.. maybe you can use suspend events for the paging toolbar , to disable the load from the moveFirst function .. i hope this helps .. i haven't tried itLheureux
i try with suspendEvents: true, and pagingToolbar.moveFirst() but i see in firebug two rwwquest on server!Chichi
I've looked in the code of the pagingtoolbar and it recalculates the paging data on the store load, it could be just a problem of refreshing the view. Maybe you can set a breakpoint in ext-all-debug.js (if you are using this one, otherwise you can change it to this one) in the onLoad private function of the paging toolbar class and see what page data is set for the toolbarLheureux
thanks for your answer! do you have same example?? becouse i try with ext.getCmp(id-pagetoolbar).doLayout() but this not good!Chichi
i solve it with Ext.getCmp('GrlGio').getStore().getProxy().pageParam = "1"; becouse i see documentation that pageParam need a string! than k a lots for your helpChichi
It seems that pageParam is the NAME of the page param. By default it is "page". That's why you need to specify a string. The answer here below is the correct one: store.currentPage = 1.Notable
D
17

In Ext 4, I found loadPage() worked pretty well for resetting the data store and making the paging toolbar go back to the first page. Example:

store.loadPage(1) // note: 1-based, not 0-based
Demented answered 31/1, 2013 at 1:28 Comment(0)
P
8

Guys currentPage=1 did the trick for me

before loading the store every time call the below By the way i am getting 500 results and loading in cache Pagination is for local, any way you can try this before any new search

                        var store = Ext.getStore('MyStoreS');
                        store.proxy.extraParams = { employeeId : searchStr};

                        store.currentPage = 1;

                        store.load();
Pluvial answered 29/9, 2014 at 0:19 Comment(0)
L
7

you can manualy reset the params

Ext.getCmp('GrlGio').getStore().getProxy().pageParam =1;
Ext.getCmp('GrlGio').getStore().getProxy().startParam =0;

and then do the store load. I know it looks hardcoded but it's the only solution i found...

Lheureux answered 15/9, 2011 at 15:48 Comment(8)
thanks! this is good for me! but HOW CAN I REFRESH pagingtollbar info??Chichi
with pagingToolbar.moveFirst() i do another request! so in this way, when i click on serarch button, i get 2 once the same store from serverChichi
.. maybe you can use suspend events for the paging toolbar , to disable the load from the moveFirst function .. i hope this helps .. i haven't tried itLheureux
i try with suspendEvents: true, and pagingToolbar.moveFirst() but i see in firebug two rwwquest on server!Chichi
I've looked in the code of the pagingtoolbar and it recalculates the paging data on the store load, it could be just a problem of refreshing the view. Maybe you can set a breakpoint in ext-all-debug.js (if you are using this one, otherwise you can change it to this one) in the onLoad private function of the paging toolbar class and see what page data is set for the toolbarLheureux
thanks for your answer! do you have same example?? becouse i try with ext.getCmp(id-pagetoolbar).doLayout() but this not good!Chichi
i solve it with Ext.getCmp('GrlGio').getStore().getProxy().pageParam = "1"; becouse i see documentation that pageParam need a string! than k a lots for your helpChichi
It seems that pageParam is the NAME of the page param. By default it is "page". That's why you need to specify a string. The answer here below is the correct one: store.currentPage = 1.Notable
U
6

Try this -

pagingToolbar.moveFirst();
Uxorial answered 15/9, 2011 at 15:27 Comment(1)
it's not good for me becouse i see that send two request on server! first request is store.load() and second request is with new parametres! how can i solve it?Chichi
O
5

Define following function "resetStartParam" , by overriding ext.data.store:

Ext.override(Ext.data.Store, {

            resetStartParam:function(){

                //get the latest store options
                var storeOptions=this.lastOptions;

                if(storeOptions!=undefined){

                    //get the param names
                    var pn = this.paramNames;

                    //get the params from options
                    var params=storeOptions.params;

                    //change the param start value to zero
                    params[pn.start] = 0;

                    //reset options params with this new params
                    storeOptions.params=params;

                    //apply this new options to store options
                    this.storeOptions(storeOptions);
                    }
                }
    });

Now call this function on click of your search button:

Ext.getCmp('GrlGio').getStore().resetStartParam(); 

Thats it.It should work.

Oira answered 16/4, 2012 at 6:16 Comment(1)
I used a similar override and reset this.pageSize = 10 and this.currentPage = 1 to get the same result.Hetti
S
4

I know that this is an old post but I thought I'd add in my pennies work. I'm using EXTJS 4 and had a similar problem. When I did a new search the page number etc did not reset. The solution I found, which appears to work with the nav bar automatically is using the currentPage attribute of the store. I do have a slight odd setup but doing this.currentPage = 1 when I do a new search works fine for me

Suctorial answered 22/8, 2012 at 12:15 Comment(0)
U
4

try this in your handler

Ext.getCmp('gridpanel').getStore().removeAll();
Ext.getCmp('PagingToolbar').moveFirst();

after this, put your search query and load the store accordingly

Ext.getCmp('gridpanel').getStore().load({params : { start : 0, limit : maxRecords, searchText : _searchText } });

hope it helps

Undershirt answered 31/7, 2013 at 8:29 Comment(0)
N
4

just call pagingToolbar.onLoad() after removeAll(). Plain and simple.

Notable answered 13/11, 2013 at 15:28 Comment(0)
I
3

Here is how I achieved search with paging. It only does 1 request and it refreshes the paging data.

onExecuteSearch: function(){
  var params = this.getSearchForm().getForm().getFieldValues()
      , proxy = this.getSomeGrid().getStore().getProxy();

  proxy.extraParams = params;
  this.getPagingToolbar().moveFirst();
}

getFieldValues() documentation: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic-method-getFieldValues

For more about the proxy "extraParams" look here: ExtJs4 - Store baseParams config property?

Immolation answered 1/2, 2012 at 17:50 Comment(2)
Hey @jack - I see this question is a few months old but your currently selected answer did not help me. I have solved some problems you were having with the duplicate request and the paging information not updating. Hope this helps someone.Immolation
It helped me! Just use the moveFirst() in staid of the load() function... no need for manually resetting parameters. Thanx!Tomas
S
3

This work fine (refresh correctly the paging info):

    myStore.removeAll();

    myStore.fireEvent('load', myStore, [], {});
Sulphurize answered 8/3, 2017 at 10:12 Comment(0)
K
2

Had to change the page size to 500 for printing the WHOLE store/grid, and once printed, restore the grid to the original page size of 25.

    // 500 records are now in the store and on the grid
    ux.core.grid.Printer.print(this.getOrderList());
    store.pageSize = this.displaySize;   // new page size is 25
    this.getPagingToolbar().doRefresh(); // equivalent of pressing a refresh button on the toolbar

does the trick - reloads store with the same sorters/filters/currentPage

Kopeck answered 19/2, 2015 at 16:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.