PDA

View Full Version : problem using the datawriter



Tim Toady
3 Mar 2010, 8:44 AM
Solved.

Tumac
4 Mar 2010, 12:04 AM
Can you post your solution or describe how you fixed?

Tim Toady
4 Mar 2010, 5:54 AM
The problem was that when calling the save function on my store the datawriter wasn't working properly. Remove was not being called and create was being called instead of update. Looking into firebug showed that phantom was not being set properly which was causing the writer to mess up. It all boiled down to the fact that I didn't have a field named 'id'. It would have been nice to have that requirement in the documentation.

Mike Robinson
4 Mar 2010, 8:09 AM
Here is what happened:

Every host-side record must have a primary (or at least unique) key, specified in the "idProperty" of the Store. This will correspond to the "id" field.

For a new record, ExtJS will generate its own temporary, "phantom," record-id. When it submits a create request and receives a list of records in response, it replaces each one of the phantom records (still uniquely identified by its ExtJS-generated ID) with the real ones, which now will carry the host-generated ID.

This process, like updating, is completely dependent upon ExtJS knowing what a unique identifier of each host-side record is. If you see records "piling up," or not losing their updated status at the right times, yada yada yada, "look at this first."

("I've got this scar here, and this bruise over here ..." he said, rolling up his sleeve, "and this bump over on my wrist from slamming it into the keyboard... and ...") :>

Tumac
4 Mar 2010, 8:31 AM
But am still having that problem. What are you using on the backend to interpret and parse the data.

maybe I am not including some function properly. I found the writer examples and restful PHP examples fairly convoluted and tried to shortcut by creating a case statement for each xaction. (case create do this, case destroy do this, case....)

I guess the question is, if you use api in your proxy, do you need to set up the backend php like the examples or is there a different method that can be used? I also have this problem if i use a straight URL and method: "POST"

Right now, if I create a record, it inserts it into my DB properly, comes back to the row to edit. Any changes I make to that row, send CREATE statements back to the databse and I get multiple inserts.

On row deleting, I am using a straight AJAX call from the RowEditor. This is working fine except when I delete the last record in the grid, it deletes it from the DB but the store/grid not updating properly and removing that last record from the view.

Tim Toady
4 Mar 2010, 1:00 PM
The backend in that example is complicated. You do not have to do it like that. JS doesn't know anything about the backend. All it knows is what it receives back from it. Having a proxy with only urls in it simply sends the data to different places rather than one.

Tumac
4 Mar 2010, 1:14 PM
What are you sending back after inserting to the url? Another thing I found lacking in documentation. I saw a post that indicated you need to send the complete record back. I am pretty sure I am sending the complete record back, but....still stabbing. So close but so far....

Tim Toady
4 Mar 2010, 1:44 PM
I haven't written the insert yet. I know for the removal I had to echo '{"success":true}'; for the datawriter to not add it back to the store. My other create/update functions are empty functions at the moment. Just look at the examples response in firebug.

Tumac
4 Mar 2010, 1:50 PM
I was only echoing "success:true" early on and having the problem, so when you get to the insert we may be conversing again....thanks. I will load the example and check it out.