Results 1 to 6 of 6

Thread: Row Editor Grid - Row is added to Store twice

  1. #1
    Ext User
    Join Date
    Jul 2009
    Posts
    15

    Default Row Editor Grid - Row is added to Store twice

    Hi,

    i'm using the Row Editor Grid (just like that one in the Samples Page) in Combination with a JSON Data Store/Writer. The Problem is, that a new Row is added two times. First time, when i click the Add Button (because of the store.insert(0, e);, otherwise i won't get a new row) and a second time when i click the Update Button.

    The values from the first POST aren't useable and i also delete the row if the user presses Cancel. Any Ideas how i can disable the first POST Message?

    Update and Delete works great, just this Add Problem

    Greets and Thanks

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    How are you using the writer?

    Couldn't you simply wait for the record to be updated before you write the record?

  3. #3
    Ext User
    Join Date
    Jul 2009
    Posts
    15

    Default

    Hi,

    i got it working, but the solution is still very ugly.

    i'm nearly exactly using this Example:
    http://extjs.com/deploy/dev/examples...l/restful.html

    Just one difference, i had only set allowBlank false to prefilled fields in the JSON Reader, so the row was valide and sent. Now I set allowBlank false to a field which isn't prefilled when creating the new recoredType. So the row seems not to be valid to the JSON Writer and therefore isn't sent!?

    Greets

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    I would set autoSave to false and control when the data is written myself.

  5. #5
    Sencha User
    Join Date
    Dec 2008
    Posts
    85

    Default

    I'm having the same problem, double writes, any solution yet?

  6. #6

    Default Think I found one cause

    Quote Originally Posted by jimtyp View Post
    I'm having the same problem, double writes, any solution yet?
    Old thread but in my researching I've found this problem many times but no solutions yet.

    I'm using the metaData feature to define the fields. I've written a class in PHP to do all the CRUD management from a backend with only needing to define a few options.

    In short, what was causing my double-create was that I was returning the id in the fields[] array and also assigning it as the idProperty. It turns out, it seems, that you do not want to put your idProperty value into the fields[] as well. When you define the fields, however, it is expected that the idProperty is added as an element.

    Code:
                //go through each column we have and set up meta-data fields with
                //the proper names (non-DB field name), type, and any extra params
                $saFieldData = array();
                foreach ($this->m_saReadFields as $saField)
                {
                    if ($saField['name'] != $saMetaData['idProperty'])
                    {
                        //unset this guy, everything else goes in the map
                        unset($saField[C_DBCOLKEY]);
                        $saFieldData[] = $saField;
                    }                
                }
                $saMetaData['fields'] = $saFieldData;
    The red code is what I changed in my code. Without it, I add the idProperty record (id) to fields and get two records. With the code in place to keep that field out, I only get one create (after clicking Update).

    Including some examples of the good/bad format of the metaData:
    Code:
    {
       metaData:{
          "idProperty":"id",
          "root":"results",
          "totalProperty":"total",
          "successProperty":"success",
          "fields":[
             {                                <-- PROBLEM FIELD
                "name":"id",
                "type":"int"
             },
             {
                "name":"pretty_name",
                "type":"string"
             },
             {
                "name":"start_date",
                "type":"date",
                "dateFormat":"Y-m-d"
             },
             {
                "name":"start_time",
                "type":"string"
             },
             {
                "name":"stop_date",
                "type":"date",
                "dateFormat":"Y-m-d"
             },
             {
                "name":"stop_time",
                "type":"string"
             },
             {
                "name":"status",
                "type":"string"
             },
             {
                "name":"max_impressions",
                "type":"int"
             },
             {
                "name":"max_clicks",
                "type":"int"
             }
          ]
       },
       success:true,
       total:2,
       results:[
          {
             "id":"25",
             "pretty_name":"test",
             "start_date":"2009-10-27",
             "start_time":"12:30 AM",
             "stop_date":"2009-11-28",
             "stop_time":"01:45 AM",
             "status":"Enabled",
             "max_impressions":"2",
             "max_clicks":"2"
          },
          {
             "id":"23",
             "pretty_name":"d5d77257-c2c4-11de-a30e-1e3cd370b53b 5",
             "start_date":"2009-10-26",
             "start_time":"11:00 AM",
             "stop_date":"2009-10-26",
             "stop_time":"11:00 AM",
             "status":"Suspended",
             "max_impressions":"0",
             "max_clicks":"0"
          }
       ]
    }
    The above causes two creates. The first immediately when insert() is called, then again when Update is clicked.

    Code:
    {
       metaData:{
          "idProperty":"id",
          "root":"results",
          "totalProperty":"total",
          "successProperty":"success",
          "fields":[
             {
                "name":"pretty_name",
                "type":"string"
             },
             {
                "name":"start_date",
                "type":"date",
                "dateFormat":"Y-m-d"
             },
             {
                "name":"start_time",
                "type":"string"
             },
             {
                "name":"stop_date",
                "type":"date",
                "dateFormat":"Y-m-d"
             },
             {
                "name":"stop_time",
                "type":"string"
             },
             {
                "name":"status",
                "type":"string"
             },
             {
                "name":"max_impressions",
                "type":"int"
             },
             {
                "name":"max_clicks",
                "type":"int"
             }
          ]
       },
       success:true,
       total:2,
       results:[
          {
             "id":"25",
             "pretty_name":"test",
             "start_date":"2009-10-27",
             "start_time":"12:30 AM",
             "stop_date":"2009-11-28",
             "stop_time":"01:45 AM",
             "status":"Enabled",
             "max_impressions":"2",
             "max_clicks":"2"
          },
          {
             "id":"23",
             "pretty_name":"d5d77257-c2c4-11de-a30e-1e3cd370b53b 5",
             "start_date":"2009-10-26",
             "start_time":"11:00 AM",
             "stop_date":"2009-10-26",
             "stop_time":"11:00 AM",
             "status":"Suspended",
             "max_impressions":"0",
             "max_clicks":"0"
          }
       ]
    }
    The version above issues only one create, and that's when Update is clicked. The id as defined in idProperty is not included as a field.

    This may not solve everyone's problem with the dual creation but it fixed mine, and was extremely simple to overlook.

    Regards,
    Michael

Posting Permissions

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