PDA

View Full Version : [CLOSED] Load store using parameter to filter data



jpadgett
Feb 28, 2013, 8:05 PM
I have a gridpanel that I want to load the store based on the selection of another control. I have a SelectionChange listener on the other control, and when it fires I call the following script:



var loadStore: function (cid) {
App.LeaderboardStore.reload({ challengeId: cid });
}


Here is the gridpanel:


Html.X().GridPanel()
.ID("LeaderboardGrid")
.Header(false)
.Border(false)
.Store(Html.X().Store()
.ID("LeaderboardStore")
.AutoLoad(false)
.Proxy(
Html.X().AjaxProxy()
.Url(Url.Action("GetLeaderBoard"))
.ActionMethods(action =>
{
action.Read = HttpMethod.POST;
})
.Reader(
Html.X().JsonReader().Root("result")
)
)
.Parameters(p =>
{
p.Add(new StoreParameter("challengeId", ""));
})
.Model(
Html.X().Model()
.Fields(
new ModelField("Place"),
new ModelField("Player"),
new ModelField("Points"),
new ModelField("Movement")
)
)
)


And the controller action:


[HttpPost]
public ActionResult GetLeaderboard()
{
int challengeId = ?????

Challenge challenge = context.Challenges.Single(c => c.ChallengeId == challengeId);

return new DirectResult((from lb in context.CurrentLeaderBoards
....
}


The script is working and trying to load the store, but I get an error where I'm trying to get the challengeId that I hope the script is passing to the controller. Can someone point me in the right direction?

Thanks!

Baidaly
Feb 28, 2013, 10:45 PM
Hello!

Try the following:


App.LeaderboardStore.reload({
params: {
challengeId: cid
}
});

You should use correct syntax for the option of reload method

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-reload
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Operation

jpadgett
Mar 01, 2013, 12:59 PM
Thanks Baidaly ... I updated the syntax in the js.

But - how do I get the parameter value in my controller action? I have tried several variations:


public ActionResult GetLeaderboard(StoreParameter param)

public ActionResult GetLeaderboard(int challengeId)


public ActionResult GetLeaderboard()
{
int challengeId = Int32.Parse(X.GetCmp<Store>("LeaderboardStore").Parameters["challengeId"].ToString());


All of these end up with a null value or object not found.

jpadgett
Mar 01, 2013, 1:01 PM
Also tried this:



public ActionResult GetLeaderboard(StoreParameterCollection parms)
{
int challengeId = Int32.Parse(parms["challengeId"].ToString());

Vladimir
Mar 01, 2013, 1:05 PM
What value is contained in 'cid'?



public ActionResult GetLeaderboard(int challengeId)

this code should work correctly if cid is number

Please post runable sample demonstrates the issue
Also try to remove this


.Parameters(p =>
{
p.Add(new StoreParameter("challengeId", ""));
})

jpadgett
Mar 01, 2013, 1:17 PM
Vladimir - 'cid' is an integer, and removing the parameter worked!



Also try to remove this


1
2
3
4
.Parameters(p =>
{
p.Add(new StoreParameter("challengeId", ""));
})




I am using:


App.LeaderboardStore.reload({ params: { challengeId: cid } });



public ActionResult GetLeaderboard(int challengeId)


Thank you!