Can we customize the gantt's request payload to server?


#1

Hi. Currently, the request payload of the gantt during POST and PUT is as follows:

{
  "text": "Some title here..",
  "start_date": "2019-04-13",
  "order": 0,
  "duration": 0.2,
  "parent":0,
  ...
}

However, the API server requires the request payload to be in the following format:

{
  "id": 1,        // Only during PUT requests
   "task": {
      "text": "Some title here..",
      "start_date": "2019-04-13",
      "order": 0,
      "duration": 0.2,
      "parent":0,
      ...
   }
}

Is there a way to do this from the front end?


#2

Hi @keithmanilla!
If you want to manually control what is sent to the server, you can make use of custom routing. You can learn more about it here:
https://docs.dhtmlx.com/gantt/desktop__server_side.html#customrouting

In your case custom router will look like this:

var dp = gantt.createDataProcessor(function(entity, action, data, id) {
       var server = "api/";
        switch(action) {
            case "create":
                return gantt.ajax.post({
                    url: server  + entity,
                    data: data
                });
                break;
            case "update":
                return gantt.ajax.put({
                    url: server  + entity + "/" + id,
                    data: JSON.stringify({
                       id: data.id,
                       task: data
                   })
                });
                break;
            case "delete":
                return gantt.ajax.del({
                    url: server + entity + "/" + id
                });
                break;
        }
    });