[CLOSED] Load store using parameter to filter data

  1. #1

    [CLOSED] Load store using parameter to filter data

    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!
  2. #2
    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/#!...-method-reload
    http://docs.sencha.com/ext-js/4-1/#!...data.Operation
  3. #3
    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.
  4. #4
    Also tried this:

    public ActionResult GetLeaderboard(StoreParameterCollection parms)
    {
         int challengeId = Int32.Parse(parms["challengeId"].ToString());
  5. #5
    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", ""));
          })
    Vladimir Shcheglov
    Sr. Developer
  6. #6
    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!

Similar Threads

  1. Replies: 2
    Last Post: Nov 01, 2012, 7:24 PM
  2. Replies: 6
    Last Post: Jul 15, 2011, 2:03 PM
  3. [CLOSED] HttpProxy sample with Method='GET' to load data for store
    By inayath in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Feb 08, 2011, 3:18 PM
  4. Replies: 6
    Last Post: Nov 14, 2010, 3:08 AM
  5. [CLOSED] Ext.data.store.load()
    By RomualdAwessou in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 01, 2010, 11:24 PM

Posting Permissions