PDA

View Full Version : [CLOSED] How to access/reload store in razor views/controller



machinableed
Mar 31, 2012, 8:35 AM
Hi there,

How can I go about rebinding a store in the controller? i.e. how can I access the store in order to do something like:

this.Store1.DataSource = this.Data;
this.Store1.DataBind();

to give you some context - I have a single page with a form panel and a grid panel. The form panel gathers details and then calls into the controller to execute a query and return a collection. I now want the controller method to bind this collection to the store of the grid panel - how can I do this? Do I have to do something like what is above somehow? Or if I convert the collection into a StoreResult and return that, will the view simply handle it? How would this work with multiple stores in a single view?

Daniil
Apr 01, 2012, 4:47 PM
Hi,

I would set up HttpProxy for a Store pointing its Url to a respective controller action.

Then you will be able to reload that Store just calling its reload client side method. It will make a load request to a controller action.

Store1.reload();

machinableed
Apr 02, 2012, 1:51 AM
But how do I pass the parameters from the form panel to that controller method? I have a form panel with a direct event on the submit button which triggers a controller method - i need the response from this method to then be the datasource for the grid panel.

Daniil
Apr 02, 2012, 11:53 AM
I have a form panel with a direct event on the submit button which triggers a controller method

Please clarify - is it a common DirectEvent with Url or do you submit a FormPanel using its submit method?

machinableed
Apr 02, 2012, 12:09 PM
yes it's a standard direct event

cutdown code:



pn.Add(Html.X().FormPanel()
.Region(Region.North)
.Collapsible(true)
.Title("Enter Search Criteria")
.BodyPadding(4)
.Layout(LayoutType.Column)
.AutoHeight(true)
.Buttons(buttons =>
{
buttons.Add(Html.X().Button()
.DirectEvents(directEvents =>
{
//directEvents.Click.
directEvents.Click.Url = "/Services/Clear";
})
.Text("Clear"));

buttons.Add(Html.X().Button()
.DirectEvents(directEvents =>
{
directEvents.Click.Url = "/Services/Search";
})
.Text("Search"));

})
.Items(fields=>
{
//form fields go here.
})
pn.Add(Html.X().GridPanel()
.Region(Region.South)
.Margins("4 0 0 0")
.AutoHeight(true)
.Title("TEST PANEL")
.store(
//store stuff here
)
.columnModel(

)



Now... on the submit the form successfully submits and ends up in the correct controller method that returns a StoreResult. I want to use this store result to be the datasource for the GridPanel.

Hope this is clearer...

Daniil
Apr 02, 2012, 2:38 PM
Thanks for the clarification.

StoreResult should be used in a combination with a Store Proxy.

I can suggest to return an AjaxResult instance from a controller action and pass a data via its ExtraParamsResponse.

Example

public ActionResult Submit(/*parameters*/)
{
List<object> data = new List<object>()
{
new
{
test = "test 1"
},
new
{
test = "test 2"
}
};

AjaxResult r = new AjaxResult()
{
ExtraParamsResponse =
{
new Parameter()
{
Name = "data",
Value = JSON.Serialize(data),
Mode = ParameterMode.Raw
}
}
};

return r;
}

Then you can load that data into the Store within a DirectEvent success handler using the Store loadData method.

Store1.loadData(result.extraParamsResponse.data);