RadiantQ jQuery Gantt Package
How to Enable Column Sorting in Gantt Table at View Level?
Previous Topic  Next Topic 


We have introduced a new feature to enable column level sorting in gantt table applying sorting separately at each level. 

In below images, notice that the task names are sorted only within their level and hierarchy, thus retaining the hierarchy.


Before Sorting



After Sorting



Column sorting can be enabled by setting sortable option in table options as illustrated below,


$gantt_container.GanttControl({

    ....

    GanttTableOptions: {

        columns: columns,

        //To enable sorting

        sortable: true,

    },

    ....

});



We have provided some sortOptions to customize column sorting,


i) allowUnsort

If the option is set to,

       true (set by default) : first click on column sorts ascending, second click sorts descending and third click resets the sorting.

       false : first click on column sorts ascending, second click sorts descending and third click sorts ascending again and sorting continues.


ii) sort

       This call back function option allows us to customize the sorting logic.


iii) shouldClearSortingOnConflictingAction

       Triggered only when only conflicting Gantt operations are performed on sorted items. Return true -> to clear and cancel the action. Return false -> to just cancel the action.


$gantt_container.GanttControl({

    GanttTableOptions: {

        columns: columns,

        //To enable sorting

        sortable: true,

        sortOptions: {

            //allowUnsort: true,

            sort: function (a, b, sortingOrder) { // This is optional, see the things you can customize below

                var order = 1;

                if (sortingOrder == RadiantQ.SortingOrder.DESC)

                    order = -1;


                var columnTitle = a.column.title;

                if (columnTitle == "PredecessorIndex") {

                    // To customize the sorting with other field value.

                    if (a.ActivityView.Activity.StartTime > b.ActivityView.Activity.StartTime) {

                        return 1 * order;

                    }

                    else if (a.ActivityView.Activity.StartTime < b.ActivityView.Activity.StartTime) {

                        return -1 * order;

                    }

                    return 0;

                }


                if (a.value > b.value) {

                    return 1 * order;

                }

                else if (a.value < b.value) {

                    return -1 * order;

                }

                return 0;

            },

            shouldClearSortingOnConflictingAction: function (action) {

                // Triggered only when only conflicting Gantt operations are performed on sorted items.

                // Return true -> to clear and cancel the action. Return false -> to just cancel the action.

                var canReset = confirm("Can't perform '" + action + "' operation when Sorting is applied. Press 'OK' to clear sorting. Please perform the operation again.");

                return canReset;

            }

        }

    }

});



NOTE : Few limitations in column sorting are, 

              a) Gantt will prevent the Indent & Outdent operations that would affect the hierarchy. Sorting will have to be "cleared" to be able to Indent and Outdent.

              b) Moving rows arounds will also be disabled until you clear the Sorting.





� RadiantQ 2022. All Rights Reserved.