Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Problem with Store sync post data

  1. #1
    Sencha User
    Join Date
    Apr 2010
    Posts
    1

    Default Problem with Store sync post data

    Hello,
    I have edit 1 row with grid

    but the store post all data to url when i sync.

    code:
    Code:
    Ext.define('yhgl', {
        extend: 'Ext.data.Model',
        fields: [{
            name: 'xh',
            type: 'int',
            useNull: true
        }, 'yhbh', 'yhmc', 'yhmm','bmbh']
    });
    
    
    
    Ext.onReady(function(){
    	Ext.tip.QuickTipManager.init();
        var store = Ext.create('Ext.data.Store', {
            model: 'yhgl',
            autoLoad: true,
            autoSync: false,
            proxy: {
                type: 'ajax',
                limitParam :'',
                pageParam :'',
                startParam :'',
                api: {
                    read: 'dodb/dbo_yh_get',
                    create: 'dodb/dbo_yh_add',
                    update: 'dodb/dbo_yh_set',
                    destroy: 'dodb/dbo_yh_del'
                },
                reader: {
                    type: 'json',
                    successProperty: 'success',
                    root: 'data',
                    messageProperty: 'message'
                },
                writer: {
                    type: 'json',
                    writeAllFields: false,
                    root: 'data'
                },
                listeners: {
                    exception: function(proxy, response, operation){
                        Ext.MessageBox.show({
                            title: 'REMOTE EXCEPTION',
                            msg: operation.getError(),
                            icon: Ext.MessageBox.ERROR,
                            buttons: Ext.Msg.OK
                        });
                    }
                }
            }
        });    
    
    
        var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
            clicksToEdit: 1
        });      
    
    	var grid = Ext.create('Ext.grid.Panel', {
    	    store: store,
    	    columns: [{
    	        header: 'A',
    	        dataIndex: 'xh',
    	        flex: 1,
    	        field: {
    	            allowBlank: false
    	        }
    	    }, {
    	        header: 'B',
    	        dataIndex: 'yhbh',
    	        width: 130
    	    }, {
    	        header: 'C',
    	        dataIndex: 'yhmc',
    	        width: 70
    	    }, {
    	        header: 'D',
    	        dataIndex: 'yhmm',
    	        width: 95
    	    }, {
    	        header: 'E',
    	        dataIndex: 'bmbh',
    	        width: 55
    	    }],
    	    renderTo: 'editor-grid',
    	    width: 600,
    	    height: 300,
    	    title: 'test',
    	    frame: true,
    	    tbar: [{
    	        text: 'Save',
    	        handler : function(){
    	            store.sync();
    	        }
    	    }],
    	    plugins: [cellEditing]
    	});	    
    
    
        
    });

  2. #2
    Sencha User
    Join Date
    Apr 2007
    Posts
    9

    Default

    I confirm this behavior. When I call store.sync it posts entire store, not just the modified record (as Ext3.X did when store.save was called). Hopefully this is just a bug and will be fixed.

    Also, anybody know the reason why 'getModifiedRecords' method was removed?

  3. #3
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102

    Default

    I am also experiencing the same problem. Also, when I edit entry first and call store.sync() in the edit event, no change is made. For the second entry, it sends just the modified record and for the third and following, it sends all records of the store.

    Hope this problem gets attention of the developers and gets fixed.

  4. #4
    Sencha User
    Join Date
    Mar 2010
    Posts
    48

    Default

    I am doing a similar thing and my data gets sent to the server as only the record being edited when I press enter or click another cell.

    In your store change autoSync: false to autoSync: true

    In the proxy writer comment out writeAllFields: false
    in the grid add
    selModel: {
    selType: 'cellmodel'
    },
    plugins: [
    Ext.create('Ext.grid.plugin.CellEditing', {
    clicksToEdit: 1
    })
    ]

    try this instead of adding the CellEditing via a variable

    see if this sends data for only one record when pressing enter or clicking another cell instead of using the Save button.

  5. #5
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102

    Default

    Didnt help

    Here are parts of my code:

    Store:
    Code:
    var store = new Ext.data.Store({
            storeId:'store_grid',
            model: 'Destinations',
        autoSync: true,  // set to true as you recommended
        proxy: {
            type: 'ajax',
            url : 'http://localhost/WebContent/destinations.json',
            reader: {
                type: 'json'
            },
            writer: {
                type: 'json',
                //writeAllFields: false  // commented out as you said
                            
            }
        }
        });
    Grid:
    Code:
    selType: 'rowmodel',
        plugins: [
            Ext.create('Ext.grid.plugin.RowEditing', {
                clicksToEdit: 2
            })
    on edit function:

    Code:
    grid.on('edit', onEdit, this);
    
    function onEdit(e) {
          e.record.commit();
    };
    When I make the first change, it doesnt apply in the grid, when i make second change it sends the whole store records, when i make the 3rd and following changes, there are 2 POST messages for each change. One has only the changed records and the other has all records...

  6. #6
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102

    Default

    PS: I am a newbie and might be missing something simple...

  7. #7
    Sencha User
    Join Date
    Mar 2010
    Posts
    48

    Default

    Here is my code, it sends only the record that is being edited. The only time it sends more than one record is when multiple records are being edited.

    In the store writer I encode the data and set a root so that it sends the record as json in the root variable

    Code:
    // Set up a model to use in our Store
    Ext.define('BodyRegionData', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id', type: 'int', mapping: 'BodyRegionID'},
            {name: 'BodyRegionID', type: 'int', mapping: 'BodyRegionID'},
            {name: 'BodyRegionName', type: 'string', mapping: 'BodyRegionName'},
            {name: 'BodyRegionDescription', type: 'string', mapping: 'Description'}
        ]
    });
    
    var bodyregionstore = Ext.create('Ext.data.Store',{
        model: 'BodyRegionData',
        id: 'BodyRegionStore',
        autoLoad: true,
        autoSync: true,
            remoteSort: true,
            pageSize: 15,    
        proxy: {
             type: 'ajax',
             actionMethods: {
              //create: 'POST',
              //destroy: 'POST',
              read: 'POST',
              update: 'POST'
            },
            api:{
              read: 'BodyRegionListData.php',
              update: 'BodyRegionUpdateData.php'
            },
            reader: {
                type: 'json',
                totalProperty: 'total',
                root: 'results',
                successProperty: 'success'
                //messageProperty: 'msg'
            },
            writer:{
              encode:true,
              root: 'UPDATEBODYREGION'
            }
        }          
    });
    
    var BodyRegionListingEditorGrid = Ext.create('Ext.grid.Panel', {
        id: 'BodyRegionListingEditorGrid',
        store: bodyregionstore,
            frame: true,
        //scope: this,
        columns: [
          {
            header: 'ID',
            readOnly: true,
            dataIndex: 'BodyRegionID',
                    sortable  : true,
            width: 30
          },{
            header: 'Body Region',
            dataIndex: 'BodyRegionName',
            width: 150,
                    sortable  : true,
            editor: {
              xtype: 'textfield',
              allowBlank: false,
              maxLength: 50
              //maskRe: /([a-zA-Z0-9\s]+)$/
              }
          },{
            header: 'Description',
            dataIndex: 'BodyRegionDescription',
            width: 300,
                    sortable  : true,
            editor: {
              xtype: 'textfield',
              allowBlank: false,
              maxLength: 255
              //maskRe: /([a-zA-Z0-9\s]+)$/
              }
          }
        ],
            tbar: [
          {
            text: 'Add a Body Region',
            tooltip: 'Click to add a Body Region',
                    icon: 'icons/table-insert-row.png',
                    cls: 'x-btn-text-icon',
            handler: displayFormWindow
          }
            ],
            bbar: Ext.create('Ext.PagingToolbar', {
          pageSize: 15,
          store: Ext.data.StoreManager.lookup('BodyRegionStore'),
          displayInfo: true,
          plugins: Ext.create('Ext.ux.ProgressBarPager', {})
            }),
        //selType: 'cellmodel',
        selModel: {
          selType: 'rowmodel'
        },
        plugins: [
            Ext.create('Ext.grid.plugin.RowEditing', {
                clicksToEdit: 1
            })
        ]
    });

  8. #8
    Sencha User
    Join Date
    Mar 2010
    Posts
    48

    Default

    The most important item here to stop multiple records being sent is to place and id in your data model
    can you please paste your data model here
    for me in my data model I had to add this
    {name: 'id', type: 'int', mapping: 'BodyRegionID'},

    also look at this post
    http://www.sencha.com/forum/showthre...STs-whole-grid

    the need for an id in the data model is not well documented

  9. #9
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102

    Default

    Ah. thanks a lot. I will try using these. My model is as follows:

    Code:
    Ext.define('Destinations', {
        extend: 'Ext.data.Model',
        fields: ['name', 'number', 'timer'] // I am not specifying data types here (string, int etc.). Does it make a difference? Its working without it also.
        });
    I will let you know later if it works.

  10. #10
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102

    Default

    Hmmm. still isnt working for me

    the id field is "null" for all records. do i need to provide ids myself in the JSON file? I tried that also but didnt help. Its still sending multiple POSTs. But now, the 1st POST contains all entries and the 2nd one contains the modified entries only.

    In your data model, you map both id and the 2nd item to the same field.
    Code:
    {name: 'id', type: 'int', mapping: 'BodyRegionID'},
    {name: 'BodyRegionID', type: 'int', mapping: 'BodyRegionID'},
    I have also done the same but actually my 2nd item is a string type not int; in your case, both are int type. Should this be done?

    Here are parts of my code again:
    Code:
    Ext.define('Destinations', {
    
        extend: 'Ext.data.Model',
    
        fields: 
            [
                {name: 'id', type: 'int', mapping: 'name'},            
                {name: 'name', type: 'string', mapping: 'name'},
                {name: 'number', type: 'string', mapping: 'number'},
                {name: 'timer', type: 'int', mapping: 'timer'}
            ]
    
        });
    
    var store = new Ext.data.Store({
          storeId:'store_grid',
          model: 'Destinations',
          autoSync: true,
    
        proxy: {
            type: 'ajax',
            url : 'http://localhost/WebContent/destinations.json',
            reader: {
                root: 'results',
                type: 'json'
            },
    
            writer: {
                type: 'json',
                 //encode:true,  // Also tried by enabling it; didnt work
                  root: 'UPDATEBODYREGION',
            }
        }
    });
    
    
    
    var grid = Ext.create('Ext.grid.Panel', {
    
            id: 'grid_center',
    
        store: Ext.data.StoreManager.lookup('store_grid'),
    
        columns: [
    
            {header: 'Name',  dataIndex: 'name', flex:1,  
               editor: {
                   xtype:'textfield',
                   allowBlank:false
                }
              },
             {header: 'Number', dataIndex: 'number', width: 200,
                editor: {
                    xtype:'textfield',
                    allowBlank:false
                }
              },
              {header: 'Timer', dataIndex: 'timer', width: 125,
                  editor: {
                    xtype:'textfield',
                    allowBlank:false
                  }
               }
    
        ],
    
        selType: 'rowmodel',
    
        plugins: [
            Ext.create('Ext.grid.plugin.RowEditing', {
                clicksToEdit: 2
            })
        ],
    
        height: 500,
        listeners: 
            {
                        itemclick: function(view, record, item, index, e)
                        {
                           rowindex_global = index;
                        }
                }
    });
    
    grid.on('edit', onEdit, this);
    
    function onEdit(e) {  e.record.commit(); };
    Here is my JSON file on the server:

    Code:
    {
    "results": 
        [
            {"name":"ABC", "number":"12345678", "timer":10},
            {"name":"CDE", "number":"93415678", "timer":20},
            {"name":"EFG", "number":"05715678", "timer":30},
            {"name":"GHI", "number":"64315678", "timer":40},
            {"name":"IJK", "number":"1549678", "timer":10},
      ]
    }

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 5
    Last Post: 6 Apr 2012, 1:38 AM
  2. Store Add/Sync problem - No uniqueness By ID
    By gcallaghan in forum Sencha Touch 1.x: Bugs
    Replies: 2
    Last Post: 24 Jun 2011, 10:27 AM
  3. Ext.data.store with json POST problem
    By ymeiner in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 2 Apr 2011, 7:37 AM
  4. [CLOSED] data.Store sync() method returning error after 0.91
    By tmtrademark in forum Sencha Touch 1.x: Bugs
    Replies: 2
    Last Post: 23 Jul 2010, 2:41 PM

Posting Permissions

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