Hybrid View

  1. #1
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    80
    Answers
    3
    Vote Rating
    0
    fily55 is on a distinguished road

      0  

    Default Answered: Grid page number not changing after store.load

    Answered: Grid page number not changing after store.load


    Hi Guys,

    I have the following grid:

    Code:
     
    createSearchGrid    : function()    {
            var me = this,
            store = me.createStore(),
            columns    = me.createColumns(),
            paging = me.createPaging(store),
            topBar = me.createTopBar(),
            panel = Ext.create("Ext.grid.Panel",{
                title        : "Search",
                id            : "myGrid",
                columns     : columns,
                tbar        : topBar,
                dockedItems :  [paging],
                store       : store
            });
    The top bar looks like this:
    Code:
    createTopBar    : function(){
            var me = this,
            tbar = [],
            
            searchField    = {
                xtype        : "textfield",
                id            : "searchField"
            },
            
            searchBtn    = {
                xtype    : "button",
                text       : "Search"
                handler    : function(){
                    me.searchStore();
                }
            };
            
            tbar.push(searchField, searchBtn);
            
            return tbar;
        },
    And finally my searchStore function is as follows:
    Code:
    searchStore    : function(){
            var field = Ext.getCmp("searchField"),
            store = Ext.getCmp("myGrid").getStore(),
            value = field.getValue();
            store.load({params:{searchtext:value,page:1}});
        },
    When I refresh the store it all works fine. It loads with page param set to 1 but when the page number in the grid paging remains whatever it was last. Any ideas?

    I'm using extjs 4.1.3

  2. Never mind. When using the above method and using store.loadPage(1) when performing a search it all works fine. Hope this helps someone else as well, I find this to be pretty handy code.

  3. #2
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    80
    Answers
    3
    Vote Rating
    0
    fily55 is on a distinguished road

      0  

    Default


    Ok I changed my store to the following:

    Code:
    createStore     :  function() {
            var me = this;
            me.createDataModel();
            var store = Ext.create("Ext.data.Store", {
                model       : "model",
                id          : "myStore",
                autoLoad    : true,
                remoteSort  : true,
                pageSize    : 20,
                proxy       :  {
                       type            : "ajax",
                       noCache            : false,
                       startParam        : undefined,
                       limitParam        : undefined,
                       actionMethods:{method:'GET'},
                    url             : "query/search.jsp",
                    extraParams        : {
                        sessionkey    : me.sessionKey
                    },
                    reader           : {
                        type            : "json",
                        root            : "records",
                        totalProperty   : "total"
                    }
                }
            });
            
               store.on("beforeload",function(store,operation){    
                var field = Ext.getCmp("searchField"),
                value = field.getValue();
                   
                operation.params = {
                    searchtext : value    
                }
                   
            });
            
            return store;
        },

    The problem now is that when I search, the page isn't set back to 1. It remains in the previous page number.

  4. #3
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    80
    Answers
    3
    Vote Rating
    0
    fily55 is on a distinguished road

      0  

    Default


    Never mind. When using the above method and using store.loadPage(1) when performing a search it all works fine. Hope this helps someone else as well, I find this to be pretty handy code.

Tags for this Thread