PDA

View Full Version : store as xtype



archmisha
14 Aug 2009, 4:50 AM
Seems Ext.grid.GridPanel can receive store as:
{
xtype: 'jsonstore',
.....
}

but Ext.PagingToolbar wont accept this, only as
Ext.data.JsonStore({....});

Am i right?

hendricd
14 Aug 2009, 5:49 AM
@archmisha -- You are correct. PagingToolbar requires a reference to a real store instance when it's config is declared.

Store xtypes like 'jsonstore' have limited value for use within a gridPanel unless you twist things a bit to leverage it:



var store;
new Ext.GridPanel({

store : (store = Ext.create( {
xtype: 'jsonstore',
.....
})),

bbar : new Ext.PagingToolbar ({ store: store }),
});

archmisha
14 Aug 2009, 6:01 AM
Thank you.

I was asking because as I understand the use of xtypes is good to postpone the creation of components until it is necessary.
But if i have some tab that got PagingToolbar, i must create the store even though the whole tab maybe wont be visible at all.

I got another question for good practice.
Suppose i am writing some component and the following is a part of it.
What is the right choice of these 2 cases:
Case1 :


{
...
this.store = new Ext.data.JsonStore({...});
var grid = new Ext.grid.GridPanel({store: this.store, ...});
},

some_private_function: function()
{
...
// using the store object for something via its reference
this.store.reload({...});
...
}


Case2 :


{
...
var grid = new Ext.grid.GridPanel({store: {xtype: 'jsonstore', id: 'myStore', ...}, ...});
},

some_private_function: function()
{
...
// using the store object for something via its reference
var store = Ext.fly('myStore');
store.reload({...});
...
}


Delay creation but assign id to get the object later for use
OR
Create the object and hold a reference to it for the component internal use.

hendricd
14 Aug 2009, 6:14 AM
I just examined the source code a bit more and noticed:

GridPanel supports Ext.StoreMgr lookups. Define your store(s) first giving each a storeId. Only then will they be managed by the StoreMgr:



new Ext.data.JsonStore({ storeId:'products', ...});then, you GridPanel and PagingToolbar can leverage the store by name:



new Ext.GridPanel({

store : 'products', //GP does the lookup for you

//PagingToolbar can too:
bbar : new Ext.PagingToolbar ({ store: 'products',... }),
});

jay@moduscreate.com
14 Aug 2009, 6:17 AM
I've already placed a feature request to have the paging toolbar automatically use the store of its parent container if it is a gridpanel or dataview. This covers combos as well.

archmisha
14 Aug 2009, 6:20 AM
What are the advantages and the usages of Ext.StoreMgr?
I've never used it before.

And about my previous 2 case question, i wasnt asking only about stores, it about all kind of components. Store was just an example.

hendricd
14 Aug 2009, 6:51 AM
...

And about my previous 2 case question, i wasnt asking only about stores, it about all kind of components. Store was just an example.

That depends largely on:

- how you intend to structure your visual layouts,
- your degree of Component re-use. (No need to extend simple classes just to change the default title of a Panel sub-class.)
- will you be creating/extending existing Ext UI classes (and giving them your own xtypes) thus, encapsulating initialization and behaviors within the class versus when you instantiate them.
- will your private class methods be aware of the rendered state of the Component (I'd hope so)?
- how loosely coupled your components need to be (is one dependent on another for life in a complex layout) -- how must they communicate?

There are several threads and wiki articles on this topic (some with opposing views but there are many ways to structure things).

BTW: Ext.fly is for use on DOM Elements, not Ext Components. Use Ext.getCmp to look up those.