Gantt - toggle planned vs actual outside of gantt toolbar

3 Answers 120 Views
Gantt
Vedad
Top achievements
Rank 2
Bronze
Bronze
Veteran
Vedad asked on 09 Jul 2021, 02:55 PM

Hi,

I would like to be able to toggle planned vs actual view on gantt outside of gantt toolbar as I have a few other steps and conditions to fulfill before I show the data.

Is there any method for doing this or any way you would recommend?

Thank you and regards,

Vedad

3 Answers, 1 is accepted

Sort by
0
Accepted
Neli
Telerik team
answered on 14 Jul 2021, 09:30 AM

Hi Vedad,

You could use the setOptions method in order to toggle planned vs actual view. In the Dojo example linked here on an external button click the value of the showPlannedTasks option is changed. Below is the respective code:

 function changeValue(){
          var gantt = $('#gantt').data('kendoGantt')
          var showPlanned = gantt.options.showPlannedTasks
          gantt.setOptions({
               showPlannedTasks: !showPlanned
          })
 }

I hope this helps.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Vedad
Top achievements
Rank 2
Bronze
Bronze
Veteran
commented on 15 Jul 2021, 11:42 AM

Hi Neli,

thank you very much for this. I will try and I will let you know.
Does this mean that I should use this approach to change any needed property when needed?

THanks and regards,
Vedad
Neli
Telerik team
commented on 20 Jul 2021, 08:48 AM

Hi Vedad,

There are some scenarios in which using the setOptions method will not work or will not be the right solution. Using the setOptions is suitable in most cases, but not all. As mentioned in the documentation Depending on the widget, some properties may not be changed, and the method's implementation varies for each widget. Also note, 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.

Let me know in case you have additional questions.

Regards,

Neli

Vedad
Top achievements
Rank 2
Bronze
Bronze
Veteran
commented on 27 Jul 2021, 02:42 PM

Hi Neli,

thanks for your answer. I am aware of note in documentation, I just wanted to check if solution is suitable where it makes sense and where its allowed by widget.

I have tested your suggested approach, and it seems to work. Thanks a lot!
0
Vedad
Top achievements
Rank 2
Bronze
Bronze
Veteran
answered on 30 Jul 2021, 04:12 PM
Hi Neli,
I just observed one strange behavior with suggested approach - vs toolbar switch - switching on/off of actual vs planned option through setOptions seems not to clear all classes added to gantt widget when we switch on/off.

line heights remain the same as when planned tasks are visible. This is not a behavior of the switch in toolbar.

https://dojo.telerik.com/@NeliKondova/EjusUPoY
vs
https://dojo.telerik.com/AGoDAGAZ

Is this a bug with this setOption or expected behavior? To me it seems that k-gantt-planned class is not removed when this approach is taken.

Thanks
0
Neli
Telerik team
answered on 04 Aug 2021, 08:52 AM

Hi Vedad,

Thank you for pointing to the issue. I discussed the scenario with a developer from the team. In this case, we would suggest you showing/hiding the planned tasks using the example below instead of using the setOptions method:

function changeValue(){
          var gantt = $('#gantt').data('kendoGantt')
          var timeline = gantt.timeline;
          // check/uncheck the Switch 
          var showPlanned = $('#gantt input.k-gantt-planned-switch').data('kendoSwitch').check()
          $('#gantt input.k-gantt-planned-switch').data('kendoSwitch').check(!showPlanned)
          // show/hide planned tasks
          gantt.wrapper.toggleClass("k-gantt-planned");
          timeline._setPlanned(!timeline.options.showPlannedTasks);
          timeline._render(gantt.dataSource.taskTree());
          timeline._renderDependencies(gantt.dependencies.view());
        }

Here is the modified Dojo example.

Note, that in the example above private methods are used which we usually do not recommend. As exposing a suitable method for showing/hiding planned tasks is a good idea I logged a Feature Request on your behalf. Below you will find a link to it. I will encourage you to cast a vote for the request.

- https://feedback.telerik.com/kendo-jquery-ui/1530410-expose-public-method-for-showing-hiding-the-planned-tasks-in-gantt

Let me know in case you have any other questions regarding the issue. 

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.

Tags
Gantt
Asked by
Vedad
Top achievements
Rank 2
Bronze
Bronze
Veteran
Answers by
Neli
Telerik team
Vedad
Top achievements
Rank 2
Bronze
Bronze
Veteran
Share this question
or