Writing a custom plugin for Ext Gantt 3.x

Since the Gantt 3.0 release is getting closer, it’s time to get a bit more familiar with it. Ext Gantt is currently in Beta-1 stage and the next beta is coming soon. In this post we’ll look at how to write a custom plugin which visually groups child task of a parent task. Here’s an image of what it should achieve.

Writing a plugin skeleton

Writing an Ext JS 5 plugin is a very simple task, and it should be done in the same way as in Ext JS 4. We simply subclass the Ext.AbstractPlugin class and implement the init method called during initialization.

In the init method, we have access to the Gantt panel to which the plugin instance is attached. Here we will do any setup that needs to be done for our plugin. In our case, we first need some sort of Template that we will use for the rendering. We can simply put this directly on the class prototype. This template needs to be used as the parentTaskBodyTemplate which controls the inner content of every parent task. We simply append a bit of markup to each existing parent task to make sure we don’t break the default rendering.

We also save a reference to the Gantt panel and its task store since we need them later.

Template and rendering

Next step is to do the actual sizing of the rendered custom elements in the view. To do this, we need to listen to a few different events of the Gantt view as you can see below.

As you can see, we want to react to each full refresh, row update, row removal and to each new row being added. For each such event we simply resize all visible task group elements, all we need to do is to set a new proper height, which we can get by asking the view for the last child of each parent (recursively). Below is the full implementation, which in total is only 70 lines of JS and a little CSS. You can try the example out yourself here:

A little CSS to finish it off:

Summing up

Time to give this example a try! Note that it is based on Ext JS 5 and our first Gantt 3 beta release. We hope this plugin can be useful for you and that it demonstrates how easy it is to take control over the Gantt rendering process to customize the appearance of the chart. Let us know what you think and if you have other ideas of useful plugins. Happy hacking!

Leave a Comment