grid default sort direction

8 posts, 0 answers
  1. NaveRonen
    NaveRonen avatar
    5 posts
    Member since:
    Feb 2013

    Posted 18 Feb 2013 Link to this post

    When clicking on a grid column header which is sortable, the first click will sort asc, then the second click on the header will sort desc and a third click will cancel the sort

    is there any way to reverse this order so the first click will sort desc, second click asc and last click no sort?


  2. Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    2622 posts

    Posted 19 Feb 2013 Link to this post

    Hi Nave,

    I am afraid what you would like to achieve is not supported in Kendo UI Grid. As a possible workaround I can suggest setting the initial sort options in the DataSource. For example: 

    dataSource = new kendo.data.DataSource({
       //....
       sort: ({ field: "FirstName", dir: "desc" })
    });
      
    $("#grid").kendoGrid({
       //....
       dataSource: dataSource
    });

    Regards,
    Iliana Nikolova
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Igor Stanek
    Igor Stanek avatar
    14 posts
    Member since:
    Jan 2008

    Posted 03 Oct 2014 in reply to Iliana Nikolova Link to this post

    Hi!

    We are very interested in this feature (the first click will sort desc, second click asc and last click no sort), too.

    Is this still not supported in KendoUI grid? And if not, it is planned?

    thanks,
    Igor.




  4. Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    2622 posts

    Posted 07 Oct 2014 Link to this post

    Hi Igor,

    This feature is currently not supported by Kendo UI Grid. Actually this idea has been submitted as a feature request at our UserVoice portal - if you wish you may cast a vote, leave a comment or monitor the community's interest in it here. The more votes the suggestion collects, the higher priority will have.

    Regards,
    Iliana Nikolova
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  5. Dirk
    Dirk avatar
    27 posts
    Member since:
    Aug 2013

    Posted 15 Apr 2016 Link to this post

    Hi,

    I think I solved this problem by modifying the DOM elements responsible fo column sorting.

    In endRequest event of the dataSource the following function is executed:

    function reverseSortOrderSequence() {
     
                setTimeout(function() {
                    var colSortHeaders = $("#gridId [data-role='columnsorter']");
                    $.each(colSortHeaders, function(index, item) {
                        if ($(item).attr("data-dir") === undefined) {
                            $(item).attr("data-dir", "asc");
                        } else if ($(item).attr("data-dir") === "asc") {
                            $(item).attr('data-dir', 'desc');
                        } else if ($(item).attr("data-dir") === "desc") {
                            $(item).attr('data-dir', null);
                        }
                    });
                });
            }

    This reverts the sort order sequence to: none->desc->asc->none...

     

    HTH

    Dirk

  6. Dirk
    Dirk avatar
    27 posts
    Member since:
    Aug 2013

    Posted 15 Apr 2016 in reply to Dirk Link to this post

    I forgot to tell that this solution is more or less a 'hack' since it uses manipulating DOM instead of using API and may not work with future version of the kendo lib.
  7. Saranya
    Saranya avatar
    11 posts
    Member since:
    Apr 2013

    Posted 27 Apr 2016 in reply to Dirk Link to this post

    I will be hooking into the dataBinding method and testing the number of dataBind events that this triggers. Would this be the preferred method as apposed to hacking the DOM and causing reflow / redraw?
  8. Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    2622 posts

    Posted 29 Apr 2016 Link to this post

    Hi Saranya,

    We are not aware of a good and universal approach which we could suggest, however I will leave this forum thread open for someone from the community to be able to get involved.

    Regards,
    Iliana Nikolova
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top