1. #1
    Ext User
    Join Date
    Jan 2008
    Posts
    12
    Vote Rating
    0
    juanramoney is on a distinguished road

      0  

    Default [3.0] Ext.data.store DataWriter ¿can I send one request when I add some records?

    [3.0] Ext.data.store DataWriter ¿can I send one request when I add some records?


    When I add some records to a store and use commitChanges or save, it sends one request to the server for each record, ¿Is there any way to do it in one request?

    thanks

  2. #2
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,361
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    I have not really worked with writer yet, so I don't know if there is a config option.

    I know that Direct does this.

  3. #3
    Ext User shibubh's Avatar
    Join Date
    Jul 2007
    Location
    Lamahi,Dang Nepal
    Posts
    449
    Vote Rating
    0
    shibubh is on a distinguished road

      0  

    Default


    yes you can do this

    store has batchSave config option
    code snipped from the writer example
    Code:
    var store = new Ext.data.Store({
    	id: 'user',
    	root: 'records',
    	proxy: proxy,
    	reader: reader,
    	writer: writer,		// <-- plug a DataWriter into the store just as you would a Reader
    	paramsAsHash: true,
    	batchSave: true// 
    });
    
    
    and the use 
    
    store.save();
    
    
    to save
    Shibu Bhattarai

    Use JavaScript beautifier to beautify you code http://jsbeautifier.org/

    Code Conventions http://javascript.crockford.com/code.html

    ExtJS Core Manual http://extjs.com/products/extcore/manual/

  4. #4
    Ext User
    Join Date
    Jan 2008
    Posts
    12
    Vote Rating
    0
    juanramoney is on a distinguished road

      0  

    Default


    the API says:

    batchSave : Boolean

    Defaults to false, which requires manually calling save to send all modifiedRecords to the server. Specify true for the store to automatically save records to the server when a record changes.

    The problem is when I add for example 2 records and save, I expect it sends an array with the changes but it sends 2 requests. I attached and image with what shows firebug.

    thanks
    Attached Images

  5. #5
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    This functionality was demoed at the conf, so it may be that it was fixed post-RC1. Can you post a testcase?

  6. #6
    Ext User
    Join Date
    Jan 2008
    Posts
    12
    Vote Rating
    0
    juanramoney is on a distinguished road

      0  

    Default


    A simple test:

    Code:
    Ext.onReady(function() {
        /*record*/
        var rProf = Ext.data.Record.create(['id', 'Nombre', 'Apellidos', 'Correo']);
    
        /*store*/
        var lProf = new Ext.data.Store({
            root: 'records',
            proxy: new Ext.data.HttpProxy({
                prettyUrls: false,
                url: 'datos.php?op=mprof'
            }),
            reader: new Ext.data.JsonReader({
                totalProperty: 'total',
                successProperty: 'success',
                idProperty: 'id',
                root: 'data'
            },
            rProf),
            writer: new Ext.data.JsonWriter({
                returnJson: true,
                writeAllFields: false
            }),
            paramsAsHash: true,
            batchSave: false
        });
        /*new records*/
        var nr = new rProf({
            Nombre: 'test1',
            Apellidos: 'Atest1'
        });
    
        var nr2 = new rProf({
            Nombre: 'test2',
            Apellidos: 'Atest2'
        });
    
        /*add records*/
        lProf.add(nr);
        lProf.add(nr2);
        /*save changes*/
        lProf.save();
    });
    And what shows firebug.

    thanks
    Attached Images

  7. #7
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    6
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    I'm just poking my nose in here. But it says batchSave. The api actions are different aren't they? So you're looking for something like batchCreate it seems.

  8. #8
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    6
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    Edit: I wasn't at the conference so I don't really know what I'm talking about...

  9. #9
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    6
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    Looking at the source it appears the create action is set up to fire the requests individually, not as an array.

  10. #10
    Ext User shibubh's Avatar
    Join Date
    Jul 2007
    Location
    Lamahi,Dang Nepal
    Posts
    449
    Vote Rating
    0
    shibubh is on a distinguished road

      0  

    Default


    Quote Originally Posted by juanramoney View Post
    A simple test:

    Code:
            paramsAsHash: true,
            batchSave: false
    And what shows firebug.

    thanks

    change batchSave:true and check the fireBug response
    Shibu Bhattarai

    Use JavaScript beautifier to beautify you code http://jsbeautifier.org/

    Code Conventions http://javascript.crockford.com/code.html

    ExtJS Core Manual http://extjs.com/products/extcore/manual/