Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS4 - Store per panel instance?

I'm really new to the MVC pattern in Ext. I have a tabpanel with multiple instances of the same component (let's call it product), each should call the server when it's opened, with an id parameter.

Right now, in order to create these tabs - I use this in the Product controller Which creates a new instance of a view, but I feel like it's really incorrect.

createMainView: function (opts) {
    return Ext.widget("productDisplay", opts);
}

I call it from my "main" controller, like this:

var tab = this.application.getController("Products")
    .createMainView({ productId : id, closable: true })

tabs.add(tab);
tabs.setActiveTab(tab);

What's the correct way to properly use multiple instances of a view, each having an instance of one store and behavior (via the controller).

Can I use one named store for them (with a js file under app/store/product.js)?

Should I manually call load on the store from the controller (to pass the productId), or is there a nicer way?

like image 968
Madd0g Avatar asked Apr 16 '12 13:04

Madd0g


People also ask

What is panel ExtJS?

Panel is a container that has specific functionality and structural components that make it the perfect building block for application-oriented user interfaces. Panels are, by virtue of their inheritance from Ext. container. Container, capable of being configured with a layout, and containing child Components.

What is ExtJS store?

The Store class encapsulates a client side cache of Model objects. Stores load data via a Proxy, and also provide functions for sorting, filtering and querying the model instances contained within it.

What is listeners in ExtJS?

Built-in Events Using ListenersExt JS provides listener property for writing events and custom events in Ext JS files. We will add the listener in the previous program itself by adding a listen property to the panel. This way we can also write multiple events in listeners property.

What is Proxy in ExtJS?

Proxies operate on the principle that all operations performed are either Create, Read, Update or Delete. These four operations are mapped to the methods create, read, update and erase respectively. Each Proxy subclass implements these functions. The CRUD methods each expect an Ext.


1 Answers

It's kind of very broad and interesting question which require big and thorough explanation (which you can find btw on the Sencha.com in their guides and manuals). I would like highlight couple points so you have something to start with:

  1. Stores are usually global objects. You don't keep two instances of one store in general. You can use filtering (local or remote) if you need to present information from the that store in several different views. The only time you would need to clone store is if you want to present different information from that store in 2+ different views at the same time.

  2. Controllers are usually spawned by main application object. You don't have to do anything special - just list them in the controllers: [] property. And then spawed when application is launched (before their views are created and rendered). Keep that in mind.

  3. If you have modal view - it's ok to create it manually and either re-use it or destroy and re-create later. You can add filtering and loading to controller which creates these views. And you can re-use same view/controller objects for different tabs if you want.

  4. If your views are presenting one instance of an object (like one product is displayed on each tab) - don't attach stores to those views. Just pass them individual model (record).

like image 178
sha Avatar answered Sep 24 '22 22:09

sha