1. #1
    Sencha User
    Join Date
    Apr 2012
    Location
    Linz, AT
    Posts
    31
    Answers
    1
    Vote Rating
    1
    drindal is on a distinguished road

      0  

    Default Answered: Store not updating Server-side (ExtJs 4.1)

    Answered: Store not updating Server-side (ExtJs 4.1)


    Hi everybody,

    I have a problem with synchronizing my store with the server side. I have a grid, with a store, which loads successfully. When clicking on a cell, i fill another form, do some changes, and update the grid's record.

    Then I have a save button, which should write the whole store back to the server and there is my problem. the store.sync() method doesn't do anything.

    My store:
    Code:
    Ext.define('ConfDemo.store.GUI_ConfigClassStore', {    extend : 'Ext.data.Store',
    
    
        requires : ['ConfDemo.model.GUI_CLASS_CONFIG'],
    
    
        constructor : function(cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                storeId : 'guiconfigclass',
                model : 'ConfDemo.model.GUI_CLASS',
                autoLoad : true,
                proxy : {
                    type : 'ajax',
                    url : ConfDemo.config.host + '?action=getGUIClassesConfig&sap-client=' + ConfDemo.config.mandt,
                    reader : {
                        type : 'json',
                        root : 'GUI_CLASSES'
                    },
                    writer : {
                        type : 'json',
                        writeAllFields : true,
                        root : 'GUI_CLASSES',
                        encode : true
                    }            
                }            
            }, cfg)]);
        }
    });
    Update Record: done in the change event of a combobox
    Code:
    record.set('TYPE', newValue);
    Save Event, for writting back to store:
    Code:
    var store = Ext.data.StoreManager.lookup('guiconfigclass');            var modifyrec = store.getModifiedRecords(); //always returns [] ????
                        store.sync({
                    callback : function(batch, options) {
                        // Callback action here
                    },
    
    
                    failure : function(batch, options) {
                        console.log(batch)
                    }
                });
    When I look at the JS Console, there is no request sent back to the server, when calling sync().

    What do I miss? I don't want to send every single change back to server, only when pressing the save button, the whole store content should be returned to the server. How can I do that?

    Thanks for every hint!!

  2. Thanks for your time!

    JsonWriter or XMLWriter doesn't write associated Data, only the model

    I found the solution to my problem:

    http://www.sencha.com/forum/showthre...w-data-package
    http://www.sencha.com/forum/showthre...a&p=652277

    So I have to override the Json or XML writer to send nested models:

    with the code bellow I have successfully sent a json string back to server.

    Code:
    proxy : {
    	type : 'ajax',
    	url : ConfDemo.config.host + '?action=getGUIClassesConfig&sap-client=' + ConfDemo.config.mandt,
    	reader : {
    		type : 'json',
    		root : 'GUI_CLASSES'
    	},
    	writer : new Ext.data.JsonWriter({
    		writeAllFields : true,
    		root : 'GUI_CLASSES',
    		getRecordData : function(record) {
    			Ext.apply(record.data,record.getAssociatedData());
    			return record.data; 
    		}
    	}),
    
    
    	listeners : {
    		exception : function(proxy, response, operation) {
    			Ext.MessageBox.show({
    				title : 'REMOTE EXCEPTION',
    				msg : operation.getError(),
    				icon : Ext.MessageBox.ERROR,
    				buttons : Ext.Msg.OK
    			});
    		}
    	}
    },

  3. #2
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,098
    Answers
    113
    Vote Rating
    96
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    either the value is not being changed in the grid's store due to some mistake or you might have some problem in your model. please post your grid store's model also. Do you have an id field ('id')? Take a look at this:

    http://docs.sencha.com/ext-js/4-0/#!...cfg-idProperty

    to check if the record was actually modified, you can do the following after you set some field in the record:

    Code:
    console.log(store.getUpdatedRecords());
    If this returns null, that means that the record was not changed in the grid's store.

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Location
    Linz, AT
    Posts
    31
    Answers
    1
    Vote Rating
    1
    drindal is on a distinguished road

      0  

    Default


    thanks for you reply,

    console.log(store.getUpdatedRecords()); returns my record, which I have modified.

    I don't have an id property, because if there is no explicit ID field, there will be one created. Now I have tried it with an id property, but there's no change.

    But I think I know whats happening:

    My Grid's model:
    Code:
    Ext.define('ConfDemo.model.GUI_CLASS', {
        extend: 'Ext.data.Model',
    
    
        uses: [
            'ConfDemo.model.CLASS_DATA',
            'ConfDemo.model.CLA_CH_AT'
        ],
    
    
        fields: [
            {
                name: 'CLASS'
            },
            {
                name: 'DESCRIPTION'
            }
        ],      
        idProperty:'CLASS',
        hasOne: {
            associationKey: 'CLASS_DATA',
            model: 'ConfDemo.model.CLASS_DATA'
        },
    
    
        hasMany: {
            associationKey: 'CLA_CH_AT',
            model: 'ConfDemo.model.CLA_CH_AT',
            primaryKey: 'CHARACT',
            name: 'characteristics'
        }
    });
    And my model, where I want to set some fields.


    Code:
    Ext.define('ConfDemo.model.CLA_CH_AT', {    extend: 'Ext.data.Model',
    
    
        uses: [
            'ConfDemo.model.GUI_CLASS'
        ],
    
    
        fields: [
            {
                name: 'CHARACT'
            },
            {
                name: 'DESCR'
            },
            {
                name: 'ENTRY_REQ'
            },
            {
                name: 'TYPE'
            }
        ],
        
        idProperty:'CHARACT',
    
    
        belongsTo: {
            model: 'ConfDemo.model.GUI_CLASS'
        }
    });
    when I check getUpdatedRecords() on the sub-store, I find the changed record. But if I to the same on the grid's store, which only displays the first level of my nested store, it doesn't find any changed records.

    I think, the getUpdatedRecords() method only looks for changes in the current level and not in sub-models (hasMany associations).

    Am I correct?

    I try to set the new value:
    Code:
    onLM_CharactConfigChange : function(combobox, newValue, oldValue, eOpts) {        
        var gpanel = combobox.up('fp_layoutmanagement').down('gridpanel[name=gp_class_config]');
        var griditem = gpanel.getSelectionModel().getSelection();
        var store = griditem[0].characteristics();        
        var record = store.getAt(store.findExact('CHARACT', combobox.name));        
        record.set('TYPE', newValue);
        console.log(store.getUpdatedRecords());    //returns [record]
    },
    and in the save-button-event I want to write the whole store back to the server:
    Code:
    var gpanel = item.up('fp_layoutmanagement').down('gridpanel[name=gp_class_config]');
    var store = gpanel.getStore();
    var modifyrec = store.getModifiedRecords();  // in the consolelog: []
    var updatedrec = store.getUpdatedRecords(); // in the consolelog: []
    
    
    store.sync({
        callback : function(batch, options) {
            console.log(batch);
        },
    
    
        failure : function(batch, options) {
            console.log(batch)
        }
    });
    While writing this post, I came up with following solution:

    When I set the griditem-record to dirty, then the getUpdatedRecords() will return the record and a write request is sent.

    So I think there's no other way than setting all root-model elements to dirty, to force the whole store to be sent back to the server. Am I right?

  5. #4
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,098
    Answers
    113
    Vote Rating
    96
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    I dont have experience with sub-models so cant say if that is causing your problem. one other suggestion is to define the idPropery which you are using to type int in your model. e.g.

    name: 'CHARACT', type: 'int'

    and likewise for the other model. see if this helps.

  6. #5
    Sencha User
    Join Date
    Apr 2012
    Location
    Linz, AT
    Posts
    31
    Answers
    1
    Vote Rating
    1
    drindal is on a distinguished road

      0  

    Default


    Thanks for your time!

    JsonWriter or XMLWriter doesn't write associated Data, only the model

    I found the solution to my problem:

    http://www.sencha.com/forum/showthre...w-data-package
    http://www.sencha.com/forum/showthre...a&p=652277

    So I have to override the Json or XML writer to send nested models:

    with the code bellow I have successfully sent a json string back to server.

    Code:
    proxy : {
    	type : 'ajax',
    	url : ConfDemo.config.host + '?action=getGUIClassesConfig&sap-client=' + ConfDemo.config.mandt,
    	reader : {
    		type : 'json',
    		root : 'GUI_CLASSES'
    	},
    	writer : new Ext.data.JsonWriter({
    		writeAllFields : true,
    		root : 'GUI_CLASSES',
    		getRecordData : function(record) {
    			Ext.apply(record.data,record.getAssociatedData());
    			return record.data; 
    		}
    	}),
    
    
    	listeners : {
    		exception : function(proxy, response, operation) {
    			Ext.MessageBox.show({
    				title : 'REMOTE EXCEPTION',
    				msg : operation.getError(),
    				icon : Ext.MessageBox.ERROR,
    				buttons : Ext.Msg.OK
    			});
    		}
    	}
    },

Thread Participants: 1