PDA

View Full Version : Row Editor Grid - Row is added to Store twice



fugo
10 Aug 2009, 4:37 AM
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

Condor
10 Aug 2009, 5:28 AM
How are you using the writer?

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

fugo
10 Aug 2009, 6:41 AM
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/restful/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

Condor
10 Aug 2009, 7:01 AM
I would set autoSave to false and control when the data is written myself.

jimtyp
21 Sep 2009, 10:54 AM
I'm having the same problem, double writes, any solution yet?

mmartinek
28 Oct 2009, 4:53 PM
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.


//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:


{
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.


{
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