Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1145
Change sort click behaviour on grid column header
posted

Hi

I have a request to change the behaviour of the sorting feature on our grids.

What the user would like is to have the following behaviour:

  • Column is unsorted
  • User clicks column header: column sorted 
  • User clicks column header: column sorted in opposite direction
  • User clicks column header: column unsorted

rather than having to press shift click.

What would be the recommended approach to achieve this?

Regards

Aidan

Parents
  • 16310
    Suggested Answer
    Offline posted

    Hi Aidan,

    You can use the firstSortDirection property and then handle the columnSorting event. The whole code will look like this:

        features: [
        {
             name: "Sorting",
             firstSortDirection: "descending",
             columnSorting: function (evt, ui) {
                  if((ui.owner.option("firstSortDirection") == ui.direction) && ui.owner.grid.dataSource.settings.sorting.expressions.length  != 0) {
                         ui.owner.clearSorting();
                          return false;
                  }
            }
        }

    This code will execute when user tries to sort a column for third time as the provided scenario. The clearSorting method removes the current sorting(for all sorted columns) and updates the UI.

    Please be aware that this will only work for 15.1. Let me know if you use lower version of IgniteUI so that I can modify my code accordingly.

Reply Children