Tips & Tricks: How to Extend Node Sorting Criteria in VARCHART XGantt

Posted by Frank Köhnen on May 21, 2014 8:40:00 AM

Assume you want to visualize a list of tasks in a Gantt chart. In addition you need to sort these tasks in descending order to get a better overview of what task you should work on next. Typically, VARCHART XGantt supports up to 3 criteria to sort tasks. With this blog post from our VARCHART XGantt tips & tricks series we show you an approach how to expand these number of criteria.

How to sort nodes in VARCHART XGantt

Let's say, we have 15 groups all filled with nodes. All of the nodes are already sorted like this:

  • 1. Criteria: start-date in ascending order
  • 2. Criteria: priority in descending order
  • 3. Criteria: ID - so that even if start-date and priority are the same the plan has a deterministic order

VARCHART XGantt Tip - Node Sorting1

Every node represents a task. Let us further assume that one of the groups contains the unassigned tasks and the other 14 groups represent machines with assigned tasks. Imagine, you want to see tasks with a certain status at the top of the "unassigned tasks" group.

So how could you achive this?

  • You could create another grouping-level to differentiate the states, but you would only need that extra level in the "unassigned tasks" group and not the other 14. This is not possible for only one group.
  • You could recreate the grouping structure as a hierarchy, but that would cause some considerable amount of work changing existing code and functionality just to show some tasks at the top of a group. This is not feasible.

So what to do? Simply use a 4th sorting criteria.

Extending the sorting criteria

You can combine the values that would be in the new first and second criteria, save this combination into a newly added field in the node and change the first node sorting criteria to this new field.
This way we effectively use 4 sorting criteria while only using all 3 available criteria in VARCHART XGantt.

To stick to our example we would sort the nodes like this:

  • 1. Criteria: status ascending is an Integer
  • 2. Criteria start-date ascending is a DateTime
  • 3. Criteria: priority descending is an Integer as well
  • 4. Criteria: ID is a String

Now you have to combine the 1st and 2nd criteria and save the combined value into a new Field.
The type of this new field will be String, because this is the only type that would let us combine an Integer with a DateTime.

Please keep in mind that by using a String field the values will be sorted alphanumerically. That means Integers in a String field will be sorted not by their value but by their leading characters.
For example the numbers 1 - 12 would look like this:
To let them be sorted by value we have to fill these number up with leading "0"s until the length of the longest number is reached:

With that in mind we use the sortable format for DateTimes, i.e. "yyyyMMddhhmmss", as well and we are good to go. Now we just have to combine those two values as a string and save it into the new field.
When this is finished for all nodes we just have to call SortNodes() on the XGantt instance and the rest will be handled by VARCHART XGantt.


Not yet developing .NET Gantt chart applications with XGantt? Give it a try!

VARCHART XGantt free trial - Gantt chart control .NET

Topics: Windows Forms Gantt Control, XGantt development tricks, Gantt Best Practice, Gantt Chart Controls