Results 1 to 3 of 3

Thread: Direct Store Not Working

  1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
      0  

    Default Answered: Direct Store Not Working

    Good day all!!! I have a store that I'm attaching to a grid.

    Store..

    Code:
    Ext.define('Firm_Matters.store.Contact',
    {
        extend          : 'Ext.data.Store',
        id              : 'Contact',
        autoLoad        : false,
        autoSave        : false,
        autoSync        : true,
        remoteSort      : true,
        model           : 'Firm_Matters.model.Contact',
        proxy           : {
                            type        : 'direct',
                            reader      : {
                                            type            : 'json',
                                            successProperty : 'success',
                                            messageProperty : 'message',
                                            totalProperty   : 'total',
                                            root            : 'data',
                                            idProperty      : 'Contact_RowID'
                                        },
                            writer      : {
                                            type            : 'json',
                                            encode          : false,
                                            writeAllFields  : true
                                        },
                            api         : {
                                            create          : Firm_Matters.ContactHandler.Create_Contact,
                                            read            : Firm_Matters.ContactHandler.Load_Contact,
                                            update          : Firm_Matters.ContactHandler.Update_Contact,
                                            destroy         : Firm_Matters.ContactHandler.Delete_Contact
                                        },
                            listeners   : {
                                            exception       : function (proxy, response, operation) 
                                                            {
                                                                Ext.MessageBox.show(
                                                                {
                                                                    title   : 'Remote Exception: Contact',
                                                                    msg     : operation.getError(),
                                                                    icon    : Ext.MessageBox.ERROR,
                                                                    buttons : Ext.Msg.OK
                                                                });
                                                            }
                                        },
                            afterRequest: function (request, success) 
                                        {
                                            if (request.action == 'read') 
                                            {
                                                this.readCallback(request);
                                            }
                                        },
                            readCallback: function (request) 
                                        {
                                            if (!request.operation.success) 
                                            {
                                                Ext.Msg.show(
                                                {
                                                    title   : 'Contact Load Error',
                                                    msg     : 'Could not load contact. Please try again or contact your administrator.',
                                                    buttons : Ext.Msg.OK,
                                                    icon    : Ext.Msg.WARNING
                                                });
                                            }
                                        },
                            scope: this
                        }
    });
    Model...

    Code:
    Ext.define('Firm_Matters.model.Contact',
    {
        extend: 'Ext.data.Model',
        
        fields  : 
        [
            {
                name: 'Contact_RowID', 
                type: 'int'
            },
            {
                name: 'Contact_IsCompany',
                type: 'bool'
            },
            {
                name: 'Contact_DisplayName',
                type: 'string'
            },
            {
                name: 'Title_RowID',
                type: 'int'
            },
            {
                name: 'Contact_FName',
                type: 'string'
            },
            {
                name: 'Contact_SName',
                type: 'string'
            },
            {
                name: 'Contact_JobTitle',
                type: 'string'
            },
            {
                name: 'Contact_Address_01',
                type: 'string'
            },
            {
                name: 'Contact_Phone',
                type: 'string'
            },
            {
                name: 'Contact_Mobile',
                type: 'string'
            },
            {
                name: 'Contact_Email',
                type: 'string'
            },
            {
                name: 'Contact_Fax',
                type: 'string'
            },
            {
                name: 'Contact_WebSite',
                type: 'string'
            },
            {
                name: 'Contact_Notes',
                type: 'string'
            },
            {
                name: 'Contact_RegNo',
                type: 'string'
            },
            {
                name: 'Contact_TaxClearance',
                type: 'string'
            },
            {
                name: 'Bank_RowID',
                type: 'int'
            },
            {
                name: 'Bank_Code',
                type: 'string'
            },
            {
                name: 'Bank_AccountName',
                type: 'string'
            },
            {
                name: 'Bank_AccountNumber',
                type: 'string'
            },
            {
                name: 'Bank_AccountType',
                type: 'string'
            },
            {
                name: 'Bank_Reference',
                type: 'string'
            },
            {
                name: 'Contact_IsActive',
                type: 'bool'
            }
        ]
    });
    Grid placed inside panel...

    Code:
    items       : [{
                                                                xtype       : 'gridpanel',
                                                                name        : 'gridContact',
                                                                closable    : false,
                                                                resizable   : false,
                                                                draggable   : false,
                                                                border      : false,
                                                                bodyBorder  : false,
                                                                floating    : false,
                                                                frame       : false,
                                                                autoDestroy : true,
                                                                store       : 'Contact',
    //                                                            height      : 140,
                                                                margin      : '0',
                                                                region      : 'center',
    //                                                            plugins     : Ext.create('Ext.grid.plugin.RowEditing',
    //                                                                        {
    //                                                                            clicksToMoveEditor  : 1,
    //                                                                            errorSummary        : false,
    //                                                                            autoCancel          : false
    //                                                                        }),
                                                                viewConfig  : {
                                                                                stripeRows  : true,
                                                                                loadingText : 'Loading contacts...'
                                                                            },
                                                                columns     : [{
                                                                                text        : 'Contact_RowID',
                                                                                sortable    : false,
                                                                                hideable    : false,
                                                                                hidden      : true,
                                                                                dataIndex   : 'Contact_RowID'
                                                                            },
                                                                            {
                                                                                text        : 'Display Name',
                                                                                flex        : 1,
                                                                                sortable    : false,
                                                                                hideable    : false,
                                                                                dataIndex   : 'Display_Name'
                                                                            },
                                                                            {
                                                                                text        : 'Address',
                                                                                flex        : 3,
                                                                                sortable    : false,
                                                                                hideable    : false,
                                                                                dataIndex   : 'Contact_Address_01'
                                                                            },
                                                                            {
                                                                                text        : 'Phone',
                                                                                flex        : 1,
                                                                                sortable    : false,
                                                                                hideable    : false,
                                                                                dataIndex   : 'Contact_Phone'
                                                                            },
                                                                            {
                                                                                text        : 'Mobile',
                                                                                flex        : 1,
                                                                                sortable    : false,
                                                                                hideable    : false,
                                                                                dataIndex   : 'Contact_Mobile'
                                                                            },
                                                                            {
                                                                                text        : 'Email',
                                                                                flex        : 1,
                                                                                sortable    : false,
                                                                                hideable    : false,
                                                                                dataIndex   : 'Contact_Email'
                                                                            },
                                                                            {
                                                                                xtype       : 'actioncolumn',
                                                                                cls         : 'tasks-icon-column-header tasks-edit-column-header',
                                                                                width       : 24,
                                                                                icon        : '../../ext-4.2.0/resources/images/edit_task.png',
                                                                                iconCls     : 'x-hidden',
                                                                                tooltip     : 'Edit',
                                                                                menuDisabled: true,
                                                                                sortable    : false,
                                                                                handler     : Ext.bind(this.handleEditContactClick, this)
                                                                            }]
                                                            }]
    My problem is that with this code as it is, when I try to load the panel I get the following error from fire bug...

    TypeError: c is undefined

    But if I comment out
    'store : 'Contact','
    for the grid it works fine. Is there something I'm doing wrong when I'm connecting the store or there is something wrong with the store itself???

  2. Hi,

    I've noticed that you have added some invalid options to your store and set your api values without quotes among other things. Try creating your store like this:

    Code:
    Ext.define('Firm_Matters.store.Contact', {
        extend : 'Ext.data.Store',
    
    
        requires : [
            'Firm_Matters.model.Contact'
        ],
    
    
        constructor : function (cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                        autoLoad : false,
                        autoSync : true,
                        model : 'Firm_Matters.model.Contact',
                        remoteSort : true,
                        storeId : 'Contact',
                        proxy : {
                            type : 'direct',
                            afterRequest : function (request, success) {
                                if (request.action == 'read') {
                                    this.readCallback(request);
                                }
                            },
                            readCallback : function (request) {
                                if (!request.operation.success) {
                                    Ext.Msg.show({
                                        title : 'Contact Load Error',
                                        msg : 'Could not load contact. Please try again or contact your administrator.',
                                        buttons : Ext.Msg.OK,
                                        icon : Ext.Msg.WARNING
                                    });
                                }
    
    
                            },
                            api : {
                                create : 'Firm_Matters.ContactHandler.Create_Contact',
                                read : 'Firm_Matters.ContactHandler.Load_Contact',
                                update : 'Firm_Matters.ContactHandler.Update_Contact',
                                destroy : 'Firm_Matters.ContactHandler.Delete_Contact'
                            },
                            reader : {
                                type : 'json',
                                idProperty : 'Contact_RowID',
                                messageProperty : 'message',
                                root : 'data'
                            },
                            writer : {
                                type : 'json'
                            },
                            listeners : {
                                exception : {
                                    fn : me.onDirectException,
                                    scope : me
                                }
                            }
                        }
                    }, cfg)]);
        },
    
    
        onDirectException : function (proxy, response, operation, eOpts) {
            Ext.MessageBox.show({
                title : 'Remote Exception: Contact',
                msg : operation.getError(),
                icon : Ext.MessageBox.ERROR,
                buttons : Ext.Msg.OK
            });
    
    
        }
    
    
    });
    Regards,

  3. #2
    Sencha Premium Member glopes's Avatar
    Join Date
    Jan 2013
    Location
    Chicago
    Posts
    123
    Answers
    16
    Vote Rating
    32
      0  

    Default

    Hi,

    I've noticed that you have added some invalid options to your store and set your api values without quotes among other things. Try creating your store like this:

    Code:
    Ext.define('Firm_Matters.store.Contact', {
        extend : 'Ext.data.Store',
    
    
        requires : [
            'Firm_Matters.model.Contact'
        ],
    
    
        constructor : function (cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                        autoLoad : false,
                        autoSync : true,
                        model : 'Firm_Matters.model.Contact',
                        remoteSort : true,
                        storeId : 'Contact',
                        proxy : {
                            type : 'direct',
                            afterRequest : function (request, success) {
                                if (request.action == 'read') {
                                    this.readCallback(request);
                                }
                            },
                            readCallback : function (request) {
                                if (!request.operation.success) {
                                    Ext.Msg.show({
                                        title : 'Contact Load Error',
                                        msg : 'Could not load contact. Please try again or contact your administrator.',
                                        buttons : Ext.Msg.OK,
                                        icon : Ext.Msg.WARNING
                                    });
                                }
    
    
                            },
                            api : {
                                create : 'Firm_Matters.ContactHandler.Create_Contact',
                                read : 'Firm_Matters.ContactHandler.Load_Contact',
                                update : 'Firm_Matters.ContactHandler.Update_Contact',
                                destroy : 'Firm_Matters.ContactHandler.Delete_Contact'
                            },
                            reader : {
                                type : 'json',
                                idProperty : 'Contact_RowID',
                                messageProperty : 'message',
                                root : 'data'
                            },
                            writer : {
                                type : 'json'
                            },
                            listeners : {
                                exception : {
                                    fn : me.onDirectException,
                                    scope : me
                                }
                            }
                        }
                    }, cfg)]);
        },
    
    
        onDirectException : function (proxy, response, operation, eOpts) {
            Ext.MessageBox.show({
                title : 'Remote Exception: Contact',
                msg : operation.getError(),
                icon : Ext.MessageBox.ERROR,
                buttons : Ext.Msg.OK
            });
    
    
        }
    
    
    });
    Regards,

  4. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
      0  

    Default

    Thanks for the help. It's sorted now

Tags for this Thread

Posting Permissions

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