RadiantQ WPF Gantt
Tasks Filtering
Previous Topic  Next Topic 

Tasks Filtering


Often you might require to visualize a filtered view of the tasks in your project. For example,




You could be tempted to simply filter the bound list of rows and then bind it to the gantt. However, that would break relationships between tasks within your project (dependencies, parent/child relationship, etc.). So, you will always have to bind the entire list of tasks to the gantt and then provide filtering criteria to the gantt, so that the gantt renders only the tasks you are interested in, while maintaining the relationship between the different tasks at the model level.


Filter definition


Filtering the tasks is supported in an old fashioned way. You provide a "filter function" that will be called once for each task to determine whether a task should be filtered in(shown) or out(hidden).


For example, this would be the filtering function that filters in tasks that are not yet complete and filters out tasks that are complete:



        bool IncompleteTasksFilter(IActivity activity)

        {

            if (activity.ProgressPercent == 100)

                return false;

            else

                return true;

        }



A return value of true for an activity includes that activity in the view and false will exclude the activity from the view.


Note that this function will only be called for non-summary/leaf tasks. The summary task's will be shown if there is at least one child filtered-in and hidden if all it's children are filtered out.


Once you have setup filters like this, you simply have to set the FilterActivities property of the gantt control to the above function and call the Filter method like this:


        private void IncompleteTasksFilter_Click(object sender, RoutedEventArgs e)

        {

            this.ganttControl.FilterActivites = IncompleteTasksFilter;

            this.ganttControl.Filter();

            this.statusTB.Text = "Gantt View Filter Status: Showing Only Incomplete Tasks.";

        }



In the code above, you will see that as soon as you call Filter, your filtering method will be called once for each activity in the project.


Filtering is a one time operation, so any changes made to the activity after the event will not alter its visibility. In the example above, after filtering, if a task's progress changes to 100%, it will not automatically get filtered out, you will have to trigger Filter() method again for that to happen.




Resetting Filter


Simply call the ResetFilter method to clear the filter currently applied.


            this.ganttControl.ResetFilters();



This feature is illustrated in the sample Samples\ProjectGantt\Behavior\GanttControlFiltering.




� RadiantQ 2009 - 2019. All Rights Reserved.