1. #1
    Sencha User
    Join Date
    Feb 2009
    Posts
    75
    Vote Rating
    -1
    bareflix is an unknown quantity at this point

      0  

    Default directStore with a JsonWriter sends no data with autoSave: true

    directStore with a JsonWriter sends no data with autoSave: true


    I have a directStore hooked up to a list and an edit form. It reads the data from the backend correctly, but when it saves, the data field is null. If I call store.save(), then it send the data for ALL rows, not just the ones that have changed. Here is my store setup:

    Code:
    skillStore = Ext.extend(Ext.data.DirectStore,
    {
        constructor: function (config)
        {
            var params = 
            {
                autoLoad: true,
                autoSave: true,
                paramsAsHash: false,
                totalProperty: 'count',
                root: 'result',    
                paramsAsHash: false,
                api:
                {
                    //create: CRUD.create,
                    read: orbital.Skill.read,
                    update: orbital.Skill.update,
                    //destroy: CRUD.destroy
                },
                // I don't know why the writer does not get auto created like the reader
                writer: new Ext.data.JsonWriter(
                    {
                        returnJson: true,
                        writeAllFields: true
                    }),
                storeId: 'skill',
                fields:
                [
                    {name:'id', type: 'number'},
                    {name:'name', type: 'string'},
                    {name:'default_attribute', type: 'string'},
                    {name:'description', type: 'string'},
                    {name:'type', type: 'string'}
                ],
            };
    
            config = Ext.apply (params, config);
            skillStore.superclass.constructor.call(this, config);
        }
    });
    Here is what it sends when I call:
    Code:
    this.getForm().updateRecord(this.record);
    Code:
    {"action":"Skill","method":"update","data":null,"type":"rpc","tid":3}
    any suggestions? what am I missing?
    It's taken me a while to get here, but it seems so close.

    --
    Chris Bare

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    You need to configure your writer with encode:false.

  3. #3
    Sencha User
    Join Date
    Feb 2009
    Posts
    75
    Vote Rating
    -1
    bareflix is an unknown quantity at this point

      0  

    Default


    I tried adding encode: false to the writer, but I still get the same "data":null sent to the backend.

  4. #4
    Sencha User
    Join Date
    Feb 2009
    Posts
    75
    Vote Rating
    -1
    bareflix is an unknown quantity at this point

      0  

    Default


    actually I do see one difference. it says "result": null, which is the value I set in the DirectStore for root:

    I see the updated value displayed in my grid, but is it possible that the store is not seeing the updated record? Here's what my form save does:

    this.getForm().updateRecord(this.record);

    which comes from the list via:

    var rec = this.list.getSelectionModel().getSelected();
    this.form.loadRecord(rec);

  5. #5
    Sencha User
    Join Date
    Feb 2009
    Posts
    75
    Vote Rating
    -1
    bareflix is an unknown quantity at this point

      0  

    Default


    ok, I built a cut-down test case and it is still not working. I am using version 3.2.1. Here's my test case:

    Code:
    <html>
     
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css">
      <link rel="stylesheet" type="text/css" href="css/orbital.css">
    </head>
     
    <body>
      <script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
     
      <script type="text/javascript" src="ext/ext-all-debug.js"></script>
      <script type="text/javascript" src="php/api.php"></script>
     
      <script type="text/javascript">
     
      // Path to the blank image must point to a valid location on your server
      Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';
    
    function modify ()
    {
            var rec = list.getSelectionModel().getSelected();
            rec.set ("description", "value");
            store.save ();
    }
    
    orbital.API.maxRetries = 0;
    Ext.Direct.addProvider(orbital.API);
    
        store = new Ext.data.DirectStore (
            {
                autoLoad: true,
                autoSave: false,
                root: 'result',    
                api:
                {
                    //create: CRUD.create,
                    read: orbital.Skill.read,
                    update: orbital.Skill.update,
                    //destroy: CRUD.destroy
                },
                // I don't know why the writer does not get auto created
                writer: new Ext.data.JsonWriter(
                    {
                        encode: false,
                        writeAllFields: true
                    }),
    
                fields:
                [
                    {name:'id', type: 'number'},
                    {name:'name', type: 'string'},
                    {name:'default_attribute', type: 'string'},
                    {name:'description', type: 'string'},
                    {name:'type', type: 'string'}
                ],
            });
    
        list = new Ext.grid.GridPanel (
        {
            region: 'center',
            store: store,
            columns: [
                {header: 'ID',  sortable: true, dataIndex: 'id'},
                {header: 'Name',  sortable: true, dataIndex: 'name'},
                {header: 'Default Attribute',  sortable: true, dataIndex: 'default_attribute'},
                {id: 'description', header: 'Description',  sortable: true, dataIndex: 'description'},
                {header: 'Type',  sortable: true, dataIndex: 'type'}
            ]
            
        });
    
        button = new Ext.Button (
        {
            region: 'south',
            text: "modify"
        });
    
        button.on ('click', modify);
        
    function main ()
    {
        viewport = new Ext.Viewport(
        {
            layout: 'border',
                items:
                [
                    list, button
                ]
        });
    }
    
     
      // Main application entry point
      Ext.onReady( main );
    
      </script>
    </body>
     
    </html>
    and here's what it sends when you press the modify button:
    Code:
    {"action":"Skill","method":"update","data":null,"type":"rpc","tid":3}
    I tried tracing the save function and I saw writer.json had the updated record, but I got lost in all the layers of callbacks etc.
    what am I missing?

    --
    Chris Bare

  6. #6
    Sencha User
    Join Date
    Aug 2007
    Posts
    2
    Vote Rating
    0
    freak_out is on a distinguished road

      0  

    Default


    Hi, I have the same problem. Have you found a solution to this?
    Thanks

  7. #7
    Sencha User
    Join Date
    Feb 2009
    Posts
    75
    Vote Rating
    -1
    bareflix is an unknown quantity at this point

      0  

    Default


    It's been a while, but I *think* my problem was that my backend function was declared with no parameters. I just stubbed it out, thinking I would finish it once I got the javascript side working. Well, since ext direct knows the function signature, it takes that into account and doesn't send anything if your function doesn't take any parameters.

  8. #8
    Ext JS Premium Member milanz's Avatar
    Join Date
    Aug 2007
    Posts
    47
    Vote Rating
    0
    milanz is on a distinguished road

      0  

    Default


    You just saved me a whole load of time.

    I was also trying to get it to work, thinking I'll just create a method stub (not thinking to add any arguments to the method). Added an argument to the method and BINGO - data sent!

    Thanks!

Similar Threads

  1. Replies: 5
    Last Post: 2 May 2011, 2:39 PM
  2. Store with autoSave:true doesn't auto-save
    By js_coder in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 11 Jan 2010, 12:17 PM
  3. Replies: 2
    Last Post: 29 Nov 2009, 8:47 AM
  4. Tabpanel sends only data from active panel?
    By Dumas in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 26 Mar 2009, 10:39 AM

Thread Participants: 3