Remove deleting of tasks in Gantt

1 Answer 155 Views
Gantt
James
Top achievements
Rank 1
James asked on 10 Jan 2022, 03:36 PM | edited on 10 Jan 2022, 03:36 PM

Hi, i want to remove the delete functionality for tasks within the gantt based on several aspects, one of which would be a field in the record set, another would be based on a user permission level.

I have the delete being cancelled but i'd like to stop the delete key from working and removal of the delete icon.

 

Any help would be appreciated.


Edit: we are using gantt within an MVC application

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 13 Jan 2022, 11:37 AM

Hello James,

You could prevent the deleting of task in the remove event handler as demonstrated below:

 remove: function(e) {  
    e.preventDefault();    
  }

If you need to hide the delete icon you could use the 'k-task-delete' class

 .k-task-delete{
      display: none !important
    }

When a task is edited you could hide the 'Delete' button in the edit event handler of the Gantt widget:

edit: function(){
 	$('.k-gantt-edit-form .k-gantt-delete').hide()
 },

Here is a Dojo example where the described above is demonstrated.

Let me know in case you have additional questions on the matter.

Regards,
Neli
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.

James
Top achievements
Rank 1
commented on 13 Jan 2022, 11:40 AM

Hi thanks for your answer, the hiding the delete button will help, but this would not stop the keyboard delete from not being used. Although i have disabled the delete event, i would ideally like to stop the entire ability to even start deleting so they don't even see an option.
Neli
Telerik team
commented on 18 Jan 2022, 08:38 AM

Hi James,

I would suggest you take a look at the editable.destroy and editable.confirmation options and check if setting the options to false suits your scenario.

I modified the previous Dojo example and disabled the confirmation dialog when deleting tasks.

Regards,

Neli

 

James
Top achievements
Rank 1
commented on 18 Jan 2022, 11:47 AM

Thank you.... that worked exactly as i needed.

 

In the future the client may want to make this possible depending on a value in the field. I do have certain items which change based on a field value, in the databound event is this where i need to look for changing the editable options as i have a feeling they will also make the progress update and other aspect depending on task information.

Neli
Telerik team
commented on 21 Jan 2022, 10:08 AM

Hi James, 

The editable.destroy and editable.confirmation can be used for configuring the deleting of tasks for the entire Gantt widget, not per task. 

If you need to change the options at runtime, please have in mind that - In some cases, the setOptions method can recreate and rebind the widget instance. Calling setOptions in an event handler or the respective widget is not recommended and can cause an endless loop or a JavaScript error. - as described here.

If you decide to change the configured options of the Gantt in the dataBound event handler you could use a setTimeout and set a slight delay. Also depending on the scenario, a flag might be needed. Such an approach is demonstrated in the Dojo linked here. In the example initially the editable.destroy is set to false, and then changed to true in the dataBound event handler. 

I hope this helps.

Regards,

Neli

Tags
Gantt
Asked by
James
Top achievements
Rank 1
Answers by
Neli
Telerik team
Share this question
or