Results 1 to 7 of 7

Thread: store as xtype

  1. #1
    Sencha User
    Join Date
    May 2008
    Posts
    180

    Default store as xtype

    Seems Ext.grid.GridPanel can receive store as:
    {
    xtype: 'jsonstore',
    .....
    }

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

    Am i right?

  2. #2
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966

    Default

    @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:


    Code:
    var store;
    new Ext.GridPanel({
    
      store : (store = Ext.create( {
            xtype: 'jsonstore',
            .....
           })),
    
      bbar : new Ext.PagingToolbar ({ store: store }),
    });
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  3. #3
    Sencha User
    Join Date
    May 2008
    Posts
    180

    Default

    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 :
    Code:
    {
    ...
    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 :
    Code:
    {
    ...
    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.

  4. #4
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966

    Default

    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:

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

    Code:
    new Ext.GridPanel({
    
      store : 'products',  //GP does the lookup for you
    
      //PagingToolbar can too:
      bbar : new Ext.PagingToolbar ({ store: 'products',... }),
    });
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  5. #5
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    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.

  6. #6
    Sencha User
    Join Date
    May 2008
    Posts
    180

    Default

    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.

  7. #7
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966

    Lightbulb

    Quote Originally Posted by archmisha View Post
    ...

    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.
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •