Results 1 to 6 of 6

Thread: [ExtJs 3.3] Own Store class extended from Ext.data.JsonStore doesn't work

  1. #1
    Sencha User
    Join Date
    Sep 2010
    Posts
    58

    Default [ExtJs 3.3] Own Store class extended from Ext.data.JsonStore doesn't work

    Hi all! I have a strange problem with a class that extends Ext.data.JsonStore:

    Code:
    ENCFax.module.user.Store = Ext.extend( Ext.data.JsonStore, {
    	autoLoad:			true,
    	root:				'rows',
    	idProperty:			'id',
    	fields:				ENCFax.module.user.Record,
    	proxy:				new Ext.data.HttpProxy( {
    		api:				{
    			read:				ENCFax.URL.USER.GET,
    			create:				ENCFax.URL.USER.CREATE,
    			update:				ENCFax.URL.USER.UPDATE,
    			destroy:			ENCFax.URL.USER.DELETE
    		}
    	} )
    } );
    
    Ext.reg( 'encfax.user.store', ENCFax.module.user.Store );
    Then I create a GridPanel inside a Window (also, another class that extends from Ext.grid.GridPanel):

    Code:
    w = new Ext.Window( {
    		id:				windowID,
    		title:			translations.USER.TITLE,
    		width:			700,
    		height:			350,
    		layout:			'fit',
    		autoScroll:		true,
    		items:			[ { 
    			xtype: 			'encfax.user.gridPanel',
    			id:				'encfax-user-grid',
    			iconCls: 		'icon-user-group',
    			fbar:			[ {
    				text:			translations.USER.FORM.NEW.TITLE,
    				handler:		this.showUserNewFormWindow.createDelegate( this ),
    				iconCls:		'icon-user-add'
    			} ],
    			store:			{ 
    				xtype:				'encfax.user.store'
    			}
     		} ],
    		closeAction:	'hide'
    } );
    It does create the window with the grid panel, and even it fires the GET request to load the Store, but the store is empty even after the load. The strangest part is that if I don't use my own JsonStore class and I pass a config object to the store option with the xtype "jsonstore" with exactly the same config that my own JsonStore class.. it works:

    Code:
    w = new Ext.Window( {
    		id:				windowID,
    		title:			translations.USER.TITLE,
    		width:			700,
    		height:			350,
    		layout:			'fit',
    		autoScroll:		true,
    		items:			[ { 
    			xtype: 			'encfax.user.gridPanel',
    			id:				'encfax-user-grid',
    			iconCls: 		'icon-user-group',
    			fbar:			[ {
    				text:			translations.USER.FORM.NEW.TITLE,
    				handler:		this.showUserNewFormWindow.createDelegate( this ),
    				iconCls:		'icon-user-add'
    			} ],
    			store:			{ 
                                    // SAME configuration than my own JsonStore class!
    				xtype:				'jsonstore',
                                    autoLoad:			true,
    	                        root:				'rows',
    	                        idProperty:			'id',
    	                        fields:				ENCFax.module.user.Record,
    	                        proxy:				new Ext.data.HttpProxy( {
    		                api:				{
    			               read:				ENCFax.URL.USER.GET,
    			               create:				ENCFax.URL.USER.CREATE,
    			               update:				ENCFax.URL.USER.UPDATE,
    			               destroy:			ENCFax.URL.USER.DELETE
    		}
    	} )
    			}
     		} ],
    		closeAction:	'hide'
    } );

    What could be the problem here?


    Thanks!

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    You can't specify complex properties like 'fields' and 'proxy' in the prototype. You need to move them to the constructor, e.g.
    Code:
    ENCFax.module.user.Store = Ext.extend(Ext.data.JsonStore, {
      constructor: function(config) {
        ENCFax.module.user.Store.superclass.constructor.call(Ext.apply({
          autoLoad: true,
          root: 'rows',
          idProperty: 'id',
          fields: ENCFax.module.user.Record,
          proxy: new Ext.data.HttpProxy({
            api:				{
              read: ENCFax.URL.USER.GET,
              create: ENCFax.URL.USER.CREATE,
              update: ENCFax.URL.USER.UPDATE,
              destroy: ENCFax.URL.USER.DELETE
            }
          })
        }, config));
      }
    });

  3. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    58

    Default

    Quote Originally Posted by Condor View Post
    You can't specify complex properties like 'fields' and 'proxy' in the prototype. You need to move them to the constructor, e.g.
    Code:
    ENCFax.module.user.Store = Ext.extend(Ext.data.JsonStore, {
      constructor: function(config) {
        ENCFax.module.user.Store.superclass.constructor.call(Ext.apply({
          autoLoad: true,
          root: 'rows',
          idProperty: 'id',
          fields: ENCFax.module.user.Record,
          proxy: new Ext.data.HttpProxy({
            api:				{
              read: ENCFax.URL.USER.GET,
              create: ENCFax.URL.USER.CREATE,
              update: ENCFax.URL.USER.UPDATE,
              destroy: ENCFax.URL.USER.DELETE
            }
          })
        }, config));
      }
    });
    It works like a charm thanks a lot!

    How can I determine which arguments can be specified in the prototype, and which ones should be in the constructor? or for simplicity's sake is better to always put the configs in the constructor?



    Again, thanks a lot!

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Complex types (objects, arrays etc.): NEVER.
    Simple types (string, int, boolean): Probably.

    But in general I would recommend to always use the constructor (or initComponent for components).

  5. #5
    Sencha User
    Join Date
    Sep 2010
    Posts
    58

    Default

    That tip helps a LOT. It will make me prevent a lot of bugs like the one I posted here.


    Thank you very much!

  6. #6

    Default

    The post was helpful. Thanks for the [email protected], I too have a similar issue. I have posted a new thread on this.

Similar Threads

  1. Ext.data.Store.getAt doesn't work well.
    By slm_sum in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 11 Oct 2010, 1:45 PM
  2. how to access to jsonStore raw data? store.reader.jsonData doesn't work.
    By sunrong in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 21 Jun 2010, 7:21 PM
  3. Autoload in Ext.data.Store doesn't work
    By simon in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 16 Apr 2009, 8:06 AM
  4. setting up data store in an extended class
    By rrishike in forum Ext 2.x: Help & Discussion
    Replies: 17
    Last Post: 15 Mar 2009, 3:58 AM
  5. Ext.data.store works / Ext.data.JsonStore doesn't work
    By phxx in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 28 Feb 2008, 10:14 AM

Posting Permissions

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