How to update gantt task assignments directly on datasource
3 Answers 13 Views
Al
Top achievements
Rank 1
Iron
Iron
Al asked on 03 May 2021, 10:02 AM

Using the code below I can successfully update a gantt task (I'm using a custom edit screen + custom update function). It fires off my transport update handler and axios does the update just fine.

  var task = ganttdataSource1.at(0);
  ganttdatasource1.update(task, { title: "New Title" });
  ganttdatasource1.sync()

What I can't figure out is how to update the resource assignments, doing as below seems to ignore the 'resources' property so when in the transport update handler 'resources' just has the ones that were originally set,

  var task = ganttdataSource1.at(0);
  ganttdatasource1.update(task, { 
        title: "New Title", 
        resources: {
            taskId: 111,
            resourceId: 222,
            value: 5,
        } 
    });

  ganttdatasource1.sync()

3 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 06 May 2021, 05:55 AM

Hello Al,

In order to update the resource assignment, you will have to trigger that update on the assignments DataSource:

var gantt = $("#gantt").getKendoGantt();
var ads = gantt.assignments.dataSource;
var assignement = ads.get(1); // get the assignement with an ID 1

assignement.set("ResourceID", 14);
ads.sync();

Regards,
Veselin Tsvetanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Al
Top achievements
Rank 1
Iron
Iron
answered on 06 May 2021, 12:36 PM

Thanks Veselin, I get what you're doing but when I call ads.sync() nothing happens ie. it doesn't seem to fire off my custom transport-update function as defined on my ganttdatasource.

When using the Gantt's builtin-edit screen it does fire off the transport-update as expected for the task and passes in all the assignments, should it not do the same thing if I update an assignment and then ads.sync()? (I don't have any transport-update defined specifically for assignment)

I happen to be using this in a Vue app but I think the principal would be the same.

0
Al
Top achievements
Rank 1
Iron
Iron
answered on 10 May 2021, 07:59 AM

As per above it appears that the call to ads.sync() is not necessary in my case but I couldn't get the transport-update remote call to trigger.

The trick I used is to toggle some arb value on my task object to force it to be dirty, then updating and syncing the ganttdatasource causes the remote service to be called with all assignment changes, happy days!

The process is something like this for anyone else interested:

//Update Assignment with id 1111
assignmentDS.get(1111) 
assignmentDS.set('value', 50)

//Get task with id 2222, which has assignment 1111 above
const task = ganttDS.get(2222) 
task.forceUpdate=!!task.forceUpdate
ganttDS.update(task, { new task data } )
ganttDS.sync()

Hi All,

The described approach should update the Task and the Assignments locally and will sync the Gantt DataSource with its remote (upon calling sync()). If you, however, read the Assignments data from a remote source, that source will not be updated unless configuring Transport Update action for the Assignments DS.

- by
Veselin Tsvetanov
Telerik team
on 10 May 2021, 01:17 PM
That makes sense, thanks
- by
Al
Top achievements
Rank 1
Iron
Iron
on 10 May 2021, 02:36 PM
Tags
Gantt
Asked by
Al
Top achievements
Rank 1
Iron
Iron
Answers by
Veselin Tsvetanov
Telerik team
Al
Top achievements
Rank 1
Iron
Iron
Share this question
or