javascriptphpdojodgriddstore

Update a OnDemandGrid based on dstore/Rest result in POST and not PUT


I am puzzled. I have an OnDemandGrid editable, and under it i have a dstore/Rest collection pointing to my backend (in PHP).

The OnDemandGrid is mixed with the Editor... I can edit my data, but i cannot save it. What i receive on the server side is a "POST" request to insert a full row in the collection... And i never recieve the update.

Should'nt i receive a PUT request instead? I am using id's in the data...

This is the client-side part:

function (...)
{
        var EditGrid = declare([ OnDemandGrid, Keyboard, Editor ]);
        var coll = new Rest({
                                        target: 'my.php/x/',
                                        idProperty: 'id',
                                        rangeStartParam: 'range',
                                        rangeCountParam: 'limit',
                                        sortParam: 'sort'
                                });    
        var grid = new EditGrid({ columns: { 
                                     user_name:{
                                       label: 'User name',
                                      editor: 'text',
                                      editOn: 'click, dbclick',
                                    autoSave: true,
                                 }},
                               collection: coll }, 'grid' );
        grid.startup();
}

I correctly receive the GET query to populate the table... Then, after editing a row and hitting "return", i get a POST!

The server side is a bit more complex to show here... Basically, on GET i do an SQL query and json-ize the results, while on POST i just return this:

http_response_code(201);
header("location: ".$_SERVER['PATH_INFO'].$id);

Where $id is the same ID i received from the request...

After the POST, i don't receive anything else. And in the POST data, i only ever receive a copy of the old, not modified, row... I never receive the "new" edited data.

It seems to me i should receive a PUT request at some point... I tried the browser debugger, server logs, nothing anywhere.

Can anybody help me out here?


Solution

  • I finally fixed it.

    It's very convoluted and very little documented all this mess. I had to dig into the browser debugger and dgrid/Rest source code a bit.

    So the problem was all in my REST backend. It turns out dgrid does a GET before the PUT/POST requesting the item to be modified, and it does a GET with only one record by asking for the specific "id". It make sense.

    Well, my backend would return an ARRAY with one element in it, in JSON format. This was the error! This is not properly parsed by dgrid and it led to the POST instead of PUT.

    Once i fixed the GET backend to return a single JSON item instead of an array with one JSON item inside, dgrid started sending the correct PUTs.