Ext.Net MVC - Recycling models/stores across different views

  1. #1

    Ext.Net MVC - Recycling models/stores across different views

    In relation to my other thread about using (View-)Controllers for handling events in the views in a more structured approach I have a similar question related to stores.

    We're using Ext.Net MVC and mostly define stores in the view. This works fine except that it seems impossible to re-use already defined stores. I have two views that use the exact same Store definition. The order in which these views are used is random so it is impossible to know whether or not a store definition has already been loaded and then reference it from the StoreManager (which I can't seem to find in the documentation) and there are cases where both stores are present on the same page. This gives a strange user experience: First, you unfold the first combo which does a server roundtrip and loads the contents and when you then select the second combobox it too will show a wait mask while retrieving the second set of results. This seems really unnecessary and silly and has already resulted in me being asked why that's happening.

    I like how Ext.Net gives me the ability to directly map my .NET DTOs into ExtJs objects and I'd love to harnass that feature in such a way that I can define stores and load them during application start. In ExtJs I'd use the stores array in the Application class for this. In MVC there's the App() builder which has a Stores() method accepting a collection of AbstractStore objects or the StoreNames() method accepting an array of strings.

    The first option appears only to be usable if I define ALL my stores in the same page as my call to the App() builder (which makes it an unmanageable heap of code). The second option seems only usable if I define my stores in Javascript, something I'd rather avoid since then I'd also have to define my models in Javascript.

    Is there a way to have my cake and eat it too (ie, pre-load all my stores while still writing them in razor syntax)?
  2. #2
    Hi @PatrickMBS,

    I don't think I comprehend all the scenario/requirements, but we could discuss this in greater details:

    This gives a strange user experience: First, you unfold the first combo which does a server roundtrip and loads the contents and when you then select the second combobox it too will show a wait mask while retrieving the second set of results. This seems really unnecessary and silly and has already resulted in me being asked why that's happening.
    Do you mean that Stores already preloaded its data, but then a user clicks ComboBox's triggers it reloads it again? If so, I would recommend to try .QueryMode(DataLoadMode.Local) for ComboBoxes. if it doesn't help, providing us with a test case to reproduce the problem would be appreciated.
  3. #3
    In short, I have multiple views that contain the exact same Store definition:

                .Store(Html.X().Store()
                    .ID("EventStore")
                    .PageSize(20)
                    .DataSource(Model)
                    .Model(Html.X().Model().Fields(
                        new ModelField("Id"),
                        new ModelField("FlightId"),
                        new ModelField("Description"),
                        new ModelField("EventDateType"),
                        new ModelField("NumberOfDays"),
                        new ModelField("EventDate"),
                        new ModelField("CalculatedDateTime")
                        ))
                    .Proxy(new RestProxy
                    {
                        Url = Url.Action("Get", "FlightEvent"),
                        Reader = { new JsonReader { RootProperty = "data" } },
                        API = { Read = "" },
                        ActionMethods = { Read = HttpMethod.GET }
                    })
    Right now, these stores are all defined in the Views they apply to. This results in a brittle set of views. If the Url or fields change, I'd have to comb through all my views to see if there's an outdated store/proxy definition and update that aswell. Ideally, I'd like to define my stores in 1 location, preload them all, shove em into the StoreManager and then reference them by their unique identifier.

    Is that possible?
  4. #4
    Is it maybe chaining that you want? As in this example?
    Fabrício Murta
    Developer & Support Expert
  5. #5
    @PatrickMBS

    In short, I have multiple views that contain the exact same Store definition

    ...

    If the Url or fields change, I'd have to comb through all my views to see if there's an outdated store/proxy definition and update that aswell. Ideally, I'd like to define my stores in 1 location, preload them all, shove em into the StoreManager and then reference them by their unique identifier.
    Could one approach be to subclass the Store class so that all this definition code (the same model fields etc) is written in one class, and use that in place of Store? It is a bit more boiler plate code to set up but the high reuse value could make it worth it.

    But there is one other question: is it the exact same instance you want to reuse/share everywhere? Or you want different instances that may hold different data for what is otherwise the same structure?

Similar Threads

  1. [CLOSED] Multiple selection models inside a grid panel.
    By arjunrvasisht in forum 2.x Premium Help
    Replies: 10
    Last Post: Apr 30, 2015, 11:26 AM
  2. [CLOSED] MVC Models with ext.net
    By mrazi in forum 2.x Premium Help
    Replies: 1
    Last Post: Nov 15, 2012, 6:09 PM
  3. [CLOSED] Multi-Select Tree and Selection Models
    By PhilG in forum 1.x Premium Help
    Replies: 1
    Last Post: Jun 12, 2012, 9:50 AM
  4. Replies: 0
    Last Post: Nov 23, 2011, 12:35 PM
  5. [CLOSED] dynamic selection models
    By GLD in forum 1.x Premium Help
    Replies: 1
    Last Post: Nov 02, 2011, 11:14 AM

Posting Permissions