Is there a way to add an additional field inside the data
like “project_id : <project_id value> ”:
var dp = gantt.createDataProcessor(function(entity, action, data, id) {
var server = "/api/v1/";
switch(action) {
case "create":
return gantt.ajax.post({
url: server + entity,
data: data,
// insert "project_id: project_id" inside <data>
});
gantt.refreshData();
break;
guldmi
May 20, 2019, 4:24pm
#2
Hi @keithmanilla !
You can add custom parameters to all requests sent by the data processor, using the payload property
of the setTransactionMode
parameter like this:
dp.setTransactionMode({
mode:"POST",
headers:{
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Language": "fr-FR"
},
payload:{
"project_id": "project_id"
}
}, true);
https://docs.dhtmlx.com/api__dataprocessor_settransactionmode.html
https://docs.dhtmlx.com/gantt/desktop__server_side.html#customrequestheadersandparameters
Alternativley if you use dataProcessor to manage updates, you can add these values in onBeforeUpdate event handler
var dp = gantt.createDataProcessor(...);
dp.attachEvent("onBeforeUpdate", function(id, state, data){
data.project_id = <project_id value>;
return true;
});
https://docs.dhtmlx.com/api__dataprocessor_onbeforeupdate_event.html
And when you load data to the gantt via gantt.load
, you’ll need to add a parameter directly to the request url, since gantt.load
is not affected by the dataProcessor:
gantt.load("data?project_id=123");
1 Like