1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    16
    Vote Rating
    0
    Answers
    1
    mcryan is on a distinguished road

      0  

    Default Answered: JSON Writer Submitting the entire data store on sync()

    Answered: JSON Writer Submitting the entire data store on sync()


    I have a grid that opens a window on selection of a row. In the window is a form, bound to the selected record. I have a save button that updates the forms record:

    Code:
    var active = this.up('form').getRecord();
    var form = this.up('form').getForm();
            
                        if (!active) {
                            return;
                        }
                        if (form.isValid()) {
                            form.updateRecord(active);
                        }
    For some reason, when this happens all rows in the data store are being sent to the server, rather than the record or row that I am working with. Any ideas on this?

  2. Try setting

    Code:
    idProperty : 'ID'
    on your model.

  3. #2
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    2,777
    Vote Rating
    112
    Answers
    33
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


    Post your store, reader, proxy code.

  4. #3
    Sencha User
    Join Date
    Jan 2011
    Posts
    16
    Vote Rating
    0
    Answers
    1
    mcryan is on a distinguished road

      0  

    Default


    Code:
        var store = Ext.create('Ext.data.Store', {
    	    model: 'model',
    	    autoLoad: true,
    	    autoSync: true,
    	    proxy: {
    	        type: 'ajax',
    	        actionMethods: 'POST',
    			extraParams: {
    				'action': 'get_list',
    			},
    			url: 'data.php',
    			api: {
                                 read: 'data.php',
                                 update: 'data.php?action=update_ticket'
                },
    	        reader: {
    	            type: 'json',
    	            root: 'data'
    	        },
    	        writer: {
    	            type: 'json',
    	            writeAllFields: true
    	        }
    	    }
    	});
    And then I have a button on the form that triggers the update:

    Code:
    buttons: [{
                text: 'Save',
                handler: function() {
                    if (this.up('form').getForm().isValid()) {
                    	Ext.apply(store.proxy.extraParams, {
    						'action': 'update_ticket'
    					});
    					var active = this.up('form').getRecord(),
    			            form = this.up('form').getForm();
    		
    			        if (!active) {
    			            return;
    			        }
    			        if (form.isValid()) {
    			            form.updateRecord(active);
    			        }
                    }
                }
            }]

  5. #4
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    2,777
    Vote Rating
    112
    Answers
    33
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


    model definition?

  6. #5
    Sencha User
    Join Date
    Jan 2011
    Posts
    16
    Vote Rating
    0
    Answers
    1
    mcryan is on a distinguished road

      0  

    Default


    Model:

    Code:
    Ext.define('model', {
    	    extend: 'Ext.data.Model',
    	    fields: [
    		    {name: 'ID', type: 'int'},
    		    {name: 'Status'},
    		    {name: 'WhenOpened', type: 'date', dateFormat: 'Y-m-d H:i'},
    		    {name: 'AssignedTo'},
    		    {name: 'AssignedName'},
    		    {name: 'WhenAssigned', type: 'date', dateFormat: 'Y-m-d H:i'},
    		    {name: 'Subject'},
    		    {name: 'ClosedBy'},
    		    {name: 'WhenClosed', type: 'date', dateFormat: 'Y-m-d H:i'},
    		    {name: 'StartTime', type: 'date', dateFormat: 'H:i'},
    		    {name: 'EndTime', type: 'date', dateFormat: 'H:i'},
    		    {name: 'Costs', type: 'int'}
    	    ]
    	});

  7. #6
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    2,777
    Vote Rating
    112
    Answers
    33
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


    Try setting

    Code:
    idProperty : 'ID'
    on your model.

  8. #7
    Sencha User
    Join Date
    Jan 2011
    Posts
    16
    Vote Rating
    0
    Answers
    1
    mcryan is on a distinguished road

      0  

    Default


    Magic! Mankz, thanks for the help. I wasted far too much time on this!

Thread Participants: 1