a set of dataprocessor methods
A new instance of DataProcessor can be created using createDataProcessor method. Alternatively, the dataProcessor constructor provides a legacy way to create a DataProcessor instance.
The dataprocessor object possesses the following methods and events:
const dp = gantt.createDataProcessor({
url: "/api",
mode: "REST",
});
dp.attachEvent("onAfterUpdate", (id, action, tid, response) => {
console.log("Updated task:", id);
});
const dp = gantt.createDataProcessor({
url: "/api",
mode: "REST",
});
const handlerId = dp.attachEvent("onAfterUpdate", (id, action, tid, response) => {
console.log("Updated task:", id);
});
// detach a listener
dp.detachEvent(handlerId);
const status = dp.getState(id);
dp.ignore(() => {
// won't be saved
gantt.addTask({
id: 10,
text: "Task #5",
start_date: "03-02-2025",
duration: 5
});
});
You can place data adding and deleting operations here when you don't want to save that changes on the server side.
The dp.ignore() method works similarly to gantt.silent().dp.setTransactionMode("POST", true);
To send custom HTTP request headers or additional data to the server, specify the first parameter as an object with the following properties:
"key":"value"
pairs that should be sent with a request"key":"value"
pairs that should be sent to the server together with headersdp.setTransactionMode({
mode: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Language": "fr-FR"
},
payload: {
"user_id": "12"
}
}, true);
true
(default) for "updated", false
for "not updated""updated"
by defaultdp.setUpdated(1);
dp.setUpdated(2, true, "deleted");
dp.attachEvent("onAfterUpdate", (id, action, tid, response) => {
if (action === "error") {
alert(`Server error: ${response.message}`);
}
});
Possible response statuses:
updated
inserted
deleted
invalid
error
dp.attachEvent("onBeforeDataSending", (id, state, data) => {
// Custom logic before sending data
return true;
});
The event fires for each data update request (after onBeforeUpdate
).
Returning false
from the event handler will prevent data from being sent to the server.
Possible response statuses:
updated
inserted
deleted
invalid
error
dp.attachEvent("onBeforeUpdate", (id, state, data) => {
// Custom logic before updating
return true;
});
The event fires for each updating record and before onBeforeDataSending
.
Returning false
from the event handler will prevent data from being sent to the server.
Possible response statuses:
updated
inserted
deleted
invalid
error
true
for adding an update mark, false
for removingdp.attachEvent("onRowMark", (id, state, mode, invalid) => {
// Custom logic before marking an item
return true;
});
The event is blockable. Returning false
will prevent the item from being marked.