PDA

View Full Version : store is not getting loaded when extra parameter are passed .



chandanmahajan
7 Jan 2011, 6:30 AM
Hi All,

I am implementing pagination in my application. I have the url. We need to pass some extra parameter apart from start and limit to call this url. In firefox, it is returning the response properly however, store is not getting loaded properly.


Store.load({params:{start :0,
limit :10,

/********************Extra parameter/
username:username,

endDate:endDate,



user:user
}});


After passing above parameter to the url, it is returning the response as expected. I can see the response in the firefox. But somehow, store is not getting loaded properly.

Could anybody let me know where I am going wrong or how to fix this problem?

I would really appricate if somebody quickly solve my problem.

Thanks in advance,

Regards,
chandan

darthwes
7 Jan 2011, 6:34 AM
show us your store definitinon/configuration?

chandanmahajan
7 Jan 2011, 6:38 AM
var logStore1 = new Ext.data.JsonStore({
root: 'topics',
totalProperty: 'totalCount',
remoteSort: true,
fields: [
'title', 'forumtitle', 'forumid', 'author',
{name: 'replycount', type: 'int'},
{name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
'lastposter', 'excerpt'
],
proxy: new Ext.data.HttpProxy({
url: 'http://127.0.0.1:6001/getDetails'
})
});
//logStore.load({params:{start:0, limit:5}});

var logGrid = new Ext.grid.GridPanel({
id: 'logGridId',
store: logStore1,
bodyCssClass: 'logGrid',
columns:[{
id: 'topic', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
header: "Topic",
dataIndex: 'title',
width: 420,
sortable: true
},{
header: "Author",
dataIndex: 'author',
width: 100,
//hidden: true,
sortable: true
},{
header: "Replies",
dataIndex: 'replycount',
width: 70,
align: 'right',
sortable: true
},{
id: 'last',
header: "Last Post",
dataIndex: 'lastpost',
width: 150,
sortable: true
}],
stripeRows: true,
autoScroll: true,
// paging bar on the bottom
bbar: new Ext.PagingToolbar({
pageSize: 10,
store: logStore1,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No records to display",
items:[
'-', {
pressed: true,
enableToggle:true,
text: 'Show Preview',
cls: 'x-btn-text-icon details',
toggleHandler: function(btn, pressed){
var view = logGrid.getView();
view.showPreview = pressed;
view.refresh();
}
}]
})

});
var users='["User1", "User2"]';
var username= '["admin","role1"]';
var endDate= "Sun, 17 Apr 2010 10:15:42 GMT";
var startDate ="Fri, 16 Apr 2010 10:15:42 GMT";
var user ='{"userId":"54327","roleId":"42013","roleName":"Administrator","userName":"admin"}';


logStore1.load({params:{
start : 0,
limiit :10,
username:username,
endDate:endDate,
user:user
}});

chandanmahajan
7 Jan 2011, 6:39 AM
Let me know if you need any other details on this.
Appricate the quickly reply.

darthwes
7 Jan 2011, 7:00 AM
Use the code brackets () to make it easier for people to read/use your code.

I picked up your code and got it to work first try. So it doesn't seem to be a js issue. I would point out that "limiit" is not "limit."

(1) Your store doesn't seem to have a successProperty, but seems to work regardless of that fact; I would reccomend using one, though.
(2) Your json response coming from the backend must not be correct. Mine looks like


{"totalCount":1,"topics":[{"title":"test","forumtitle":"Forum Test","forumid":12,"author":"Author Wes","replycount":121,"lastpost":1294411746,"lastposter":"LP Wes","excerpt":"Wes excerpt"}]}

(3) Your using a paging bar, so you should consider moving your params into baseParams so that paging will work properly. This lets the store remember the last set of params you gave it. The paging bar will override start and limit every time it wants a new page of data. I would do



var logStore1 = new Ext.data.JsonStore({
root: 'topics',
totalProperty: 'totalCount',
successProperty: 'succ',
remoteSort: true,
fields: ['title', 'forumtitle', 'forumid', 'author',
{
name: 'replycount',
type: 'int'
},
{
name: 'lastpost',
mapping: 'lastpost',
type: 'date',
dateFormat: 'timestamp'
}, 'lastposter', 'excerpt'],
proxy: new Ext.data.HttpProxy({
url: 'test.php'
}),
baseParams: {
start: 0,
limit: 10,
username: '',
endDate: '',
user: ''
}
});

//Then
logStore1.baseParams.username = username;
logStore1.baseParams.endDate = endDate;
logStore1.baseParams.user = user;
logStore1.load();


Keep in mind that putting start and limit on your base params is not necessary if the paging bar is going to control the store (you're not going to get a start or limit if you just manually call store.load afaik) or if your defining defaults on the backend.

chandanmahajan
7 Jan 2011, 8:23 AM
Thanks a lot,

You have solved my problem like a magic in the a minute. Really appricate the kind of response you have sent. I could solve my problem very eaisly.

The server was not sending the proper response. I have modified the api so that it is sending the proper response now.


Thanks again.