-
8 Jan 2013 12:12 PM #1
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:
The top bar looks like this: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 });
And finally my searchStore function is as follows: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; },
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?Code:searchStore : function(){ var field = Ext.getCmp("searchField"), store = Ext.getCmp("myGrid").getStore(), value = field.getValue(); store.load({params:{searchtext:value,page:1}}); },
I'm using extjs 4.1.3
-
Best Answer Posted by fily55
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.
-
8 Jan 2013 12:57 PM #2
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.
-
8 Jan 2013 1:03 PM #3
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.


Reply With Quote