а

Start_date not get updated in tree view column


#1

Hi,
updated start date using ajax call and in the success full response i update new date to task.start but it is updated in tree view column. below is my code.
if(ajaxmsg == ‘success’){

var stdate = data[i][‘stdate’];
var mydate = stdate.split("-");
var newdate = mydate[0]+","+ mydate[1]+","+ mydate[2];

var task= gantt.getTask(id);
task.start_date = new Date(newdate);
gantt.refreshData();
return true;
}
please do the needfull.


#2

Hello,

on each repaint grid cells are completely refreshed and they take values directly from the properties of tasks, there is no cache or anything like that.
If you don’t see changes in the grid, it most likely means that the data object of a related task hasn’t been modified.
You can check the task object via gantt.getTask(id) from the browser console, and if you don’t know the id of a task - you can look it up in DOM http://prntscr.com/pzgob9

Btw, regarding the way you parse dates:

var mydate = stdate.split("-");
var newdate = mydate[0]+","+ mydate[1]+","+ mydate[2];
...
task.start_date = new Date(newdate);

Using a date string constructor is usually discuraged, since it may work differently between browsers - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
If you know the format you’re getting (year-month-day or day-month-year), you can either use the helper:

var strToDate = gantt.date.str_to_date("%Y-%m-%d");
task.start_date = strToDate(stdate);

it will be more readable and less prone to errors

https://docs.dhtmlx.com/gantt/desktop__date_format.html
https://docs.dhtmlx.com/gantt/api__gantt_date_other.html

Finally, when you modify the start date, you also need to update either a duration or the end date of a task, since these properties are linked and gantt won’t know which one to update:

var strToDate = gantt.date.str_to_date("%Y-%m-%d");
task.start_date = strToDate(stdate);
task.end_date = gantt.calculateEndDate(task);

Hope something of that will help to solve your issue. If not - please attach a complete example which I can run locally and reproduce the error.


#3

Thanks for the clarification … yes this is working in single task update. the thing is am trying to assign all task to one assignee. for that in project light box i added one checkbox for apply all task . check that and choose assign click save, onlightboxsave i triggered php ajax page in successfull response i want to update start_date, duration, assignee inside the for loop.

Note : Except start_date other fields get updates

+project
+ Dev (lightboxaction)
- task1 (owner1)
- task2 (owner1)
- task3 (owner1)
- task4 (owner1)

CODE:

if(ajaxmsg == ‘success’){
for(i=0; i<4;i++){
var stdate = data[i][‘stdate’];
var duration = data[i][‘duration’];
var owner = data[i][‘owner’];
var task= gantt.getTask(id);

task.owner = owner;
var strToDate = gantt.date.str_to_date("%Y-%m-%d");
task.duration = duration;
task.start_date = strToDate(stdate);
task.end_date = gantt.calculateEndDate(task.start_date,task.duration);
gantt,updateTask(id);

gantt.refreshData();
}
return true;
}


#4

Hi!

where is data and id variables come from in your snippet?
From the code you show, the same task is updated on each iteration of the loop, the id variable never changes as far as I can see. I’m not completely sure what should happen there.

If it’s an id of a project item, changing its dates won’t take effect, since project dates are calculated from its subtasks. You’ll need to ensure you’re updating the subtasks of the project.

In order to iterate all subtasks of the affected project, you can either use gantt.getChildren:

var children = gantt.getChildren(id);
children.forEach(function(childId){
   var child = gantt.getTask(childId);
   child.start_date = ...
}

or you can use gantt.eachTask, which may be simpler https://docs.dhtmlx.com/gantt/api__gantt_eachtask.html

gantt.eachTask(function(child){
   child.start_date = ...
}, id);// be sure to specify a parent id

If it doesn’t help - can you please extend your code sample to give me a better picture of what’s happening there?


#5

Thanks i solved …
its working… initially unscheduled true
i updated unscheduled false then start_date


#6

HI,
In this scenario , I am facing another problem.
after all task assigned to owner, i called
gantt.attachEvent(“onAfterLightbox”, function () {
gantt.clearAll();
gantt.load(“URL”);
});

This function triggered after the lightbox closed.
Clear the existing task in the gantt. but the new data is not bind .
i checked console it returns new json . but the chart grid empty.


#7

Hi,

Seems working ok on my end:
https://files.dhtmlx.com/30d/efeb0751df6007877a1bf7fa12745bbf/gantt-onafterlightbox-clear-load.zip - be sure to open index.html from the web server, otherwise ajax loading won’t work

Can you please send a complete demo or give an online link to a page where the problem occurs?