How to set the default sort direction when clicking grid header column in GXT 2.2.5

grid, gwt, gxt, java

Solution

I got a different solution

I had a similar situation, in which I wanted date columns to be sorted DESC on the first click, while others should be sorted ASC on the first click. I wrote my own GridView, and inside it I overridden the onHeaderClick function like so:

    /**
     * Make sure that Date columns are sorted in a DESCENDING order by default
     */
    @Override
    protected void onHeaderClick(Grid<ModelData> grid, int column)
    {
        if (cm.getColumn(column).getDateTimeFormat() != null)
        {
            SortInfo state = getSortState();

            if (state.getSortField() != null && state.getSortField().equals(cm.getColumn(column).getId()))
            {
                super.onHeaderClick(grid, column);
                return;
            }
            else
            {
                this.headerColumnIndex = column;
                if (!headerDisabled && cm.isSortable(column))
                {
                    doSort(column, SortDir.DESC);
                }
            }
        }
        else
        {
            super.onHeaderClick(grid, column);
            return;
        }
    }

Problem

Is there a way to control the default sorting order used when first clicking a grid header? Suppose, I am having two columns one is name and another is downloads. i want to set name as `ASC` order and downloads as `DESC` on first click on grid header.that means when i first click on download column header it should be display most downloaded first. Is it possible to set initial sorting order of column?

Original source