Update Database with JSONDataConnector and custom update SQL


A short overview of my problem:
I have a grid with custom excells. In each of these excells I need to display multiple values from one DB row. So far this is working fine. But now I need to save these values back to the DB as a new row. I don’t want to overwrite the existing row in the DB. The old row should be availabe for tracking purposes. The only way is to use a DataProcessor on client side and a JSONDataConnector on the server side.
But on the server side I’m just getting a string “[object Object]” as return value. So I guess the JSONDataConnector or even the DataProcessor cannot handle a JSON Object as return value.

Here the DataProcessor on the client side.

    myGrid = myLayout.cells("a").attachGrid();

    myGrid.load("connector.php", function () {}, "json");

    myGridDataProcessor = new dataProcessor("connector.php");

And these are the POST values that were sent to the server by the DataProcessor during an update event.

    editing: "true"
    660_gr_id: "660"
    660_name: "010_0560"
    660_status: "[object Object]"
    660_!nativeeditor_status: "updated"
    660_head: "[object Object], [object Object]"
    ids: "660"

As you can see the “status” and even the predefined key “head” are sent as strings, not as objects as expected.

To prevent the JSONDataConnector from default behaviour I’m using your example
docs.dhtmlx.com/connector__php__ … processing

class EventModel{ function update($action){ echo var_dump($action->get_data()); } }
But still I’m still getting [“status”] => string(15) “[object Object]”.

So I guess something is wrong with the DataProcessor on the client side. I also tried to use the excells examples “myprice” and “mytime” but still i just got a string “[object Object]” as return value.
Just to be sure, on a excell the return value of the getValue() function is send back to the server?

I attached all neccessary files (html including js, php connector and sql dump) cleaned from all unneccessary code and with some comments.
All dhtmlx files are up to date.

Would be pretty awesome to get at least some pseudo code on how to fix this issue.

Thank you for your support in advance.
attachment.zip (4.35 KB)

try to add code like next, after dataprocessor initialization

dp.escape = function(data){ if (typeof data == "object") data = JSON.stringify(data); return encodeURIComponent(data); }

This will redefine how complex objects are serialised before sending to the server side, and instead of dummy string representation, the valid JSON data will be sent.


yes, now the header JSON and the my custom excell JSON are valid usable JSON strings on the server side. Thanks a lot!

But one additional issue I solved in the meantime:
As you can see in the previously attached connector.php I use a header with the ID “status” and at the same time a userdata index “status”. This will cause the custom excell to return the userdata instead of the actual cell data. I solved this by renaming the header ID. But maybe you can pay attention to this issue in future releases or at least make a note in the documention.

{ "head":[ { "id":"status" // <- id is equal with userdata index name // more config } ], "status":{ // <- this name is equal with header id // some more config }, "rows":[ { // row data } ] }

Thanks for your support!