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

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

  1. #1

    Default [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
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    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

    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

    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 Attached Images

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

    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

    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 Attached Images

  7. #7
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996

    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

    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

    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

    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/

Page 1 of 2 12 LastLast

Posting Permissions

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