PDA

View Full Version : [CLOSED] [RAZOR] Change the store on a GridPanel



gets_gui
Jul 18, 2012, 2:30 PM
Hi

I have a store defined on a GridPanel. Once the user clicks Search I have to change the store's content to the new query.

I have the following razor code, a backing controller and a method to make a remote call and return the results as a StoreResult.

I've followed the link

http://forums.ext.net/showthread.php?18158-CLOSED-How-to-access-reload-store-in-razor-views-controller

But I'm not sure how to get a handle to the store to call .LoadData(...)



.Add(Html.X().Panel()
.ID("Summary")
.Title("Summary")
.Split(true)
.Layout(Ext.Net.LayoutType.Accordion)
.Add(Html.X().Panel()
.ID("Panel1")
.Title("Summary")
.Add(Html.X().GridPanel()
.ID("SummaryGridPanel")
.AutoScroll(true)
.ColumnModel(columns =>
{
columns.Add(Html.X().Column()
.Text("Column1")
.DataIndex("_Column1")
);
columns.Add(Html.X().Column()
.Text("Column2")
.DataIndex("_Column1")
);
})
.Store(store => store.Add(Html.X().Store()
.ID("SummaryStore")
.Buffered(false)
.AutoLoad(false)
.Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
.Url("/Query/GetData")
.Reader(reader => reader.Add(Html.X().JsonReader()
.Root("data")
))
))
.Model(model => model.Add(Html.X().Model().Fields(fields =>
{
fields.Add(Html.X().ModelField().Name("_Column1"));
})
))
))
)
)
...

Daniil
Jul 18, 2012, 4:51 PM
Hi,

You can just call client side:

store.load({
params : {
param1 : 'param1',
param2 : 'param2'
}
});

It will initiate a load request following the Url you have specified for the AjaxProxy.

gets_gui
Jul 19, 2012, 9:46 AM
Hi Daniil

Not sure I understand your reply

I have the following controller code, GetStore() isn't intialised. From my controller code how do I reload the store?




// Get a reference to the GridPanel
var ordersGrid = X.GetCmp<GridPanel>("SummaryGridPanel");

// Get the store, this returns null
var store = ordersGrid.GetStore();

Daniil
Jul 19, 2012, 12:05 PM
You should just return a StoreResult instance setting up its Data property. You should not deal with the Store instance.

gets_gui
Jul 23, 2012, 5:00 PM
Hi Daniil

Still having issues getting this to work. I've upgrades to 2.0.0 RC-2 which has added the Store object

My store has a proxy defined on it so I'm using the LoadProxy method to load the results. When running the code I get no results in the grid.



var store = X.GetCmp<Store>("resultStore");

var results = GetStoreResults();

store.LoadProxy(results);


An additonal question is if I try and setup a AjaxResult object to to returned I always get an Invalid JSON response. Method returns a ActionResult.



r = new AjaxResult()
{
ExtraParamsResponse =
{
new Parameter()
{
Name = "result",
Value = "hello",
Mode = ParameterMode.Value
}
}
};

Daniil
Jul 23, 2012, 8:44 PM
Ok, lets clarify the requirement.

1. When do you need to load a new data into the Store?

2. Can you load that new data from the Url you have defined for the AjaxProxy?

gets_gui
Jul 24, 2012, 9:16 AM
Hi Daniil

1) I need to load data into the store once the use clicks a button. This will send a event on the messagebus to a listener/handler I have defined in the controller. In the handler I want to call the method which populates a StoreResult object (Which is correctly populated) and display this on the GridPanel which already has a AjaxProxy defined on it.

2) Yes, if I set AutoLoad to true. The URI is called and the GridPanel does populate with the correct results.

Daniil
Jul 24, 2012, 12:12 PM
Ok, thanks for the clarification.

When a user clicks the Button, you should call client side the following code:

store.load({
url : 'some url' // if you need to use another URL comparing to the AjaxProxy one.
});

An action controller should return a StoreResult.