PDA

View Full Version : Grid page number not changing after store.load



fily55
8 Jan 2013, 12:12 PM
Hi Guys,

I have the following grid:



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:


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:


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

fily55
8 Jan 2013, 12:57 PM
Ok I changed my store to the following:


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.

fily55
8 Jan 2013, 1:03 PM
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.