Results 1 to 5 of 5

Thread: Updated value of baseParams is NOT SENT to server

  1. #1
    Ext User mark_romeo87's Avatar
    Join Date
    Jul 2007
    Location
    Angeles City, Philippines
    Posts
    10

    Question Updated value of baseParams is NOT SENT to server

    How can I update the value dynamically of a variable in baseParams so that it can send it to server correctly?

    the text in red is the part of the code that I THINK would do the functionality that I want, but it seems it wont do the trick:

    Code:
    var remoteJsonStore = new Ext.data.JsonStore({
        proxy: remoteProxy,
        storeId: 'ourRemoteStore',
        root: 'records',
        baseParams: {
            "debug": 1,
            "oprtn": ""
        },
        autoLoad: false,
        totalProperty: 'totalCount',
        remoteSort: true,
        fields: recordFields,
        idProperty: 'id',
        successProperty: 'success',
        writer: writer,
        autoSave: false,
        listeners: {
            exception: function (proxy, type, action, o, response, args) {
                switch (action) {
                case "update":
                    //this.setBaseParam({oprtn:"update"});
                    this.baseParams.oprtn = "update";
                    alert(this.baseParams.oprtn);
                    break;
                case "create":
                    alert("create");
                    break;
                case "destroy":
                    this.baseParams.oprtn = "delete";
                    break;
                default:
                    alert("read");
                }
            }
        }
    });


    Heres the server response in firebug



    While here is the code for my grid

    Code:
    Ext.onReady(function () {
        Ext.BLANK_IMAGE_URL = '../../lib/extjs/resources/images/default/s.gif';
        Ext.QuickTips.init();
    
        var remoteProxy = new Ext.data.HttpProxy({
            api: {
                read: 'dataQuery.php?oprtn=r',
                create: 'dataCreate.php',
                update: 'dataUpdate.php',
                destroy: 'dataDelete.php'
            }
        });
    
        var recordFields = [{
            name: 'id',
            mapping: 'id'
        },
        {
            name: 'firstname',
            mapping: 'firstname'
        },
        {
            name: 'lastname',
            mapping: 'lastname'
        },
        {
            name: 'street',
            mapping: 'street'
        },
        {
            name: 'city',
            mapping: 'city'
        },
        {
            name: 'state',
            mapping: 'state'
        },
        {
            name: 'zipcode',
            mapping: 'zip'
        }];
    
        var writer = new Ext.data.JsonWriter({
            encode: true,
            writeAllFields: false
        });
    
        var remoteJsonStore = new Ext.data.JsonStore({
            proxy: remoteProxy,
            storeId: 'ourRemoteStore',
            root: 'records',
            baseParams: {
                "debug": 1,
                "oprtn": ""
            },
            autoLoad: false,
            totalProperty: 'totalCount',
            remoteSort: true,
            fields: recordFields,
            idProperty: 'id',
            successProperty: 'success',
            writer: writer,
            autoSave: false,
            listeners: {
                exception: function (proxy, type, action, o, response, args) {
                    switch (action) {
                    case "update":
                        //this.setBaseParam({oprtn:"update"});
                        this.baseParams.oprtn = "update";
                        alert(this.baseParams.oprtn);
                        break;
                    case "create":
                        alert("create");
                        break;
                    case "destroy":
                        this.baseParams.oprtn = "delete";
                        break;
                    default:
                        alert("read");
                    }
                }
            }
        });
    
        var grid = {
            xtype: 'editorgrid',
            columns: columnModel,
            id: 'myEditorGrid',
            store: remoteJsonStore,
            trackMouseOver: true,
            loadMask: true,
            bbar: pagingToolbar,
            stripeRows: true,
            forceValidation: false,
            viewConfig: {
                forceFit: true
            },
            listeners: {
                cellcontextmenu: doCellCtxMenu,
                destroy: function (thisGrid) {
                    if (thisGrid.rowCtxMenu) {
                        thisGrid.rowCtxMenu.destroy();
                    }
                }
            }
    
        }
    
        new Ext.Window({
            height: 350,
            width: 550,
            border: false,
            layout: 'fit',
            items: grid
        }).show();
    
        remoteJsonStore.load({
            params: {
                start: 0,
                limit: 50
            }
        });
    
    }); // eof  onReady func
    Heres the thing, whenever I do an Update in the grid then I click the Save Changes button, I want the initial value of baseParams.oprtn="" to be updated to baseParams.oprtn="update", so that i can do the right operation on the server side. Same thing to deleting a record and inserting, so the baseParams.oprtn would be "destroy" or "create".

    I dont know if the "exception" in my remoteJsonStore is the RIGHT APPROACH to it. Please anyone help me on this, i cant sleep nor eat right anymore.


    -Mark from the Philippines

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854

    Default

    Please don't post the same thread just because you don't see it immediately - post moderation is on.

  3. #3
    Ext User mark_romeo87's Avatar
    Join Date
    Jul 2007
    Location
    Angeles City, Philippines
    Posts
    10

    Default

    sorry tryanDLS, since this is my first post, I overlooked the message after I submitted my 1st post (just saw it after my 2nd post), It wont happen again.

  4. #4
    Sencha User carol.ext's Avatar
    Join Date
    Jun 2007
    Location
    Littleton, Colorado, USA
    Posts
    707

    Default

    Heres the thing, whenever I do an Update in the grid then I click the Save Changes button, I want the initial value of baseParams.oprtn="" to be updated to baseParams.oprtn="update"
    But the code you highlighted in red is inside the exception listener. Where is your Save Changes button?

  5. #5
    Ext User mark_romeo87's Avatar
    Join Date
    Jul 2007
    Location
    Angeles City, Philippines
    Posts
    10

    Default

    Hello Carol, oh I almost forgot this thread,

    yep your right, why did I put the code INSIDE THE EXCEPTION LISTENER,
    I thought "exception listener" is an event that is always invoked whenever theres
    a Delete, Create, Update, Read, in the store.
    Then I review my English diction, then read Ext Manual, read again the book Ext in Action then read searched here in the forum
    then I do this:
    Code:
    listeners: {
        beforeload: function (s, o) {
            remoteJsonStore.setBaseParam('oprtn', 'read');
        },
        beforewrite: function (hp, a, rs, o) {
            switch (a) {
            case "update":
                remoteJsonStore.setBaseParam('oprtn', 'update');
                break;
            case "create":
                remoteJsonStore.setBaseParam('oprtn', 'create');
                break;
            case "destroy":
                remoteJsonStore.setBaseParam('oprtn', 'destroy');
                break;
            default:
                remoteJsonStore.setBaseParam('oprtn', 'read');
            }
        }
       ...........
    I do this just to tell the server that I am doing delete or create or etc. and do some query,
    And realized that my approach is wrong because Ext Data.Writer is already telling the server through the variable xaction.
    Just learning this great library for a week, sorry for my lame question. thanks for reading

Posting Permissions

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