Hello,
I have recently purchased the gantt chart library with the PDF export module docker image. I am a newbie to this.
I have added a specific header using dataProcessor’s setTransactionMode in order for the backend API to accept the AJAX call. That fixed the issue for interactions on gantt chart. Now, I am having the same issue with using export to PDF since it’s not using dataProcessor but directly doing a form submit. How would I add the additional header for this case?
Currently there is no built-in way to add custom parameters to the export request form.
The only solution I can suggest is to override a private method that creates a form for the export and add an input there.
Try adding this code somewhere after dhtmlxgantt.js and export.dhtmlx.com/gantt/api.js :
[code](function(){
function patchExport(gantt){
var createForm = gantt._create_hidden_form;
gantt._create_hidden_form = function(){
var formContainer = createForm.call(gantt);
var form = formContainer.querySelector(“form”);
if(!form.querySelector(“input[name=‘csrf’]”)){
var csrfInput = document.createElement(“input”);
csrfInput.type = “hidden”;
csrfInput.name = “csrf”;
csrfInput.value = “CSRF KEY”;
form.appendChild(csrfInput);
}
return formContainer;
};
}
Thank you Ramil. This solution wouldn’t work because my API is looking for CSRF on the Request header and the override you have suggested adds it to form data.
I am thinking of overriding the method to do a $.ajax and inside success method do a window.open and pass the PDF response to it. With using $.ajax, I can add custom headers by using the header options