а

How to save Enddate


#1

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


#2

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?


#3

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


#4

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?


#5

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


#6

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


#7

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?


#8

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.


#9

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