How to save Enddate

Hello, how do I save “enddate” when I save “stratdate” and “duration”?

Hi @isWFF,
If I understand you correctly, you want to save 3 data properties( end_date , start_date and duration ). Unfortunately, you can store only 2 of them at the same time, the 3rd will be calculated automatically. So, if you need exactly end_date , you can remove start_date or duration .
API:
https://docs.dhtmlx.com/gantt/desktop__loading.html#loadingtaskdates
If I misunderstood you, could you please clarify the question?

OK, what should I do if I want to save the start date and end date now?

Hi @isWFF,
If you meant a start_date - end_date controller in the lightbox, you can add the time section to the gantt.config.lightbox.sections, like in the following snippet:
http://snippet.dhtmlx.com/66f5281b4
API:
Time control: https://docs.dhtmlx.com/gantt/desktop__time.html
Configuring lightbox: https://docs.dhtmlx.com/gantt/api__gantt_lightbox_config.html

btw, in the gantt you can change task data by using inline editing in the grid, you can read more about this functionality by the following link:
https://docs.dhtmlx.com/gantt/desktop__inline_editing.html

If it is not what you need, could you please clarify where exactly you want to save start_date and end_date, maybe you have the problem with saving dates in the database?

I want to save enddate instead of duration. The above example still saves duration, but duration is calculated by startDate and enddate

Hi @isWFF,
Sorry, I don’t think I’ve understood your question correctly.
When you save the lightbox (the details form) the task has all three properties defined - start_date/end_date/duration.
Can you please clarify what exactly do you mean by saving the end date instead of duration?
Are we talking about saving these properties to the database(backend), or are we still on how things are stored or calculated on the client-side?

btw, I updated the old example and added getting start/end dates functionality inside onLightbox/onLightboxSave events:
http://snippet.dhtmlx.com/794573366
To check how it works you should:

  1. Open console in browser developer tools
  2. Double click on a task (the start/end dates will be displayed in the console)
  3. Change dates and click save button in the lightbox (modified dates will be displayed in the console)

API:
onLightbox
https://docs.dhtmlx.com/gantt/api__gantt_onlightbox_event.html
onLightboxSave
https://docs.dhtmlx.com/gantt/api__gantt_onlightboxsave_event.html

If the data I want to save in the database is the end date and duration, is there any way to achieve it? Or although Gantt chart provides three modes for us to choose in the light box, the three modes of data saved in the database are start date and duration?

Hi @isWFF,
Thank you for the clarification.
By default, our client sends all 3 parametres (start_date, end_date, duration) to the server.
If you want to have only 2 of them saved in your database, you should change code in your server-side, which is responsible for loading and saving data, to save only two of them. I couldn’t give you more detailed recommendations without an example of your server-side code responsible for loading and saving data.

If you check any of our “How to start” tutorials, you can see how the tasks are saved to the database:
https://docs.dhtmlx.com/gantt/desktop__howtostart_dotnet_core.html#step4implementingwebapi - you’ll need to scroll down a bit until you find “TaskController” definition and the line: // PUT api/task/5.

    // PUT api/task/5
    [HttpPut("{id}")]
    public ObjectResult Put(int id, WebApiTask apiTask)
    {
        var updatedTask = (Task)apiTask;
        var dbTask = _context.Tasks.Find(id);
        dbTask.Text = updatedTask.Text;
        dbTask.StartDate = updatedTask.StartDate;
        dbTask.Duration = updatedTask.Duration;
        dbTask.ParentId = updatedTask.ParentId;
        dbTask.Progress = updatedTask.Progress;
        dbTask.Type = updatedTask.Type;

        _context.SaveChanges();

        return Ok(new
        {
            action = "updated"
        });
    }

You can see that all saved fields are listed there explicitly, you can change one for another.
The same can work for implementations in different languages, e.g.
https://docs.dhtmlx.com/gantt/desktop__howtostart_php_laravel.html#step5savingchanges

public function update($id, Request $request){
    $task = Task::find($id);

    $task->text = $request->text;
    $task->start_date = $request->start_date;
    $task->duration = $request->duration;
    $task->progress = $request->has("progress") ? $request ->  	   progress : 0;   
    $task->parent = $request->parent;

    $task->save();

    return response()->json([
        "action"=> "updated"
    ]);
}

You have full control over the code that writes changes to the database, and you should be able to configure it to fit your purposes.

I see. Thank you.
Is there any way for this control to implement reverse task scheduling, that is, to give the end date of the last task and push the end date of the previous task

Hi @isWFF,
If I understand you correctly, you wand to schedule tasks based on their end dates?
In order to do this, i can suggest you use the auto_shedule extension(available in PRO), which has the backward scheduling functionality, API:
https://docs.dhtmlx.com/gantt/desktop__auto_scheduling.html#backwardscheduling
Where you can set up the task.end_date and dependencies between tasks and I can suppose that it will work in a way you need.
Here is a sample:
https://docs.dhtmlx.com/gantt/samples/02_extensions/20_backwards_scheduling.html

I will test according to your method. When I have only one project, this method is feasible. But when I have multiple projects, I will change the end time of the last task of all projects to the specified time. Is there any way?

I just want to change the end time of the last project to the specified time, not all projects

Can you reply to me, thank you

Hi @isWFF,
If I understand correctly, you are saying that the backward scheduling feature I referred to in my previous post is what you want, but you need a way to apply backward scheduling just to a single project, not to the whole gantt?
If it is so, you can disable/enable auto-scheduling for the specific tasks using this fragment of code:

gantt.attachEvent("onBeforeTaskAutoSchedule",function(task, start, link, predecessor){
    if(!task.blocked) {
        return false;
    }
    return true;
});

Here is a snippet:
http://snippet.dhtmlx.com/227a466be
Only Task with id:6 will be auto-scheduled. Drag it to check.

API:
https://docs.dhtmlx.com/gantt/desktop__auto_scheduling.html#disablingautoschedulingforspecifictasks

I’m sorry if I’m having trouble understanding you, maybe you could share some screenshots that would illustrate how you want projects and tasks to be modified?

Hello, I’d like to tell you something about my project
There is no relationship among the three projects A, B, C. the end date of project a is 2019 / 11 / 30, the end date of project B is 2019 / 12 / 15, and the end date of project C is 2019 / 12 / 30. When I set gantt.config.project_end = new date (2019, 11, 30), the end date of three projects A, B, C will become 2019 / 12 / 30. This is not the result I want. Is there any way to set the end date of each project separately?

Hi @isWFF,
Thank you for the clarification, if I understand, you want to have 3 projects with different end-dates, and backward scheduled children, am I right?
So, you have two ways to do this:
The first way is to use schedule_from_end and constraints for the latest tasks in projects:
For the last task of each project you should set the constraint_type: mfo( must finish on) and constraint_date: finish date. So, the constraint_date of the latest task will define the end date of the parent’s project.
The data of the the latest tasks in projects would look like this code fragment:

{"id":14, "text":"Task #3", "end_date":"02-04-2018", "constraint_type":"mfo", "constraint_date":"20-05-2019","duration":"6", "parent":"11", "progress": 0.8, "open": true},

Here is a demo:
http://snippet.dhtmlx.com/1788f2e4b

API constraint types:
https://docs.dhtmlx.com/gantt/api__gantt_constraint_types_config.html

The second way to do what you need is to use the common auto-scheduling: gantt.auto_schedule() and the right dependencies between tasks.
As you can see, in the demo below, all usual tasks are connected by the links: type: 3(“start_to_finish”: “3”), which means that the target task can’t end before the source task starts (but it may end later).
When you call gantt.auto_schedule() each project will be scheduled based on its the latest task.

Here is a demo:
http://snippet.dhtmlx.com/305f0aad0

API links:
https://docs.dhtmlx.com/gantt/api__gantt_links_config.html

Note: When a user changes the date of a task by moving it with the mouse pointer or via the lightbox, the task automatically receives one of the two constraint types: either start no earlier than+%start date% or finish no later than+%end date%, depending on the chosen planning strategy: https://docs.dhtmlx.com/gantt/desktop__auto_scheduling.html#versioncompatibility