This is a migrated thread and some comments may be shown as answers.

grid default sort direction

7 Answers 1717 Views
Grid
This is a migrated thread and some comments may be shown as answers.
NaveRonen
Top achievements
Rank 1
NaveRonen asked on 18 Feb 2013, 03:18 PM
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?


7 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 19 Feb 2013, 02:26 PM
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!
0
Igor Stanek
Top achievements
Rank 1
answered on 03 Oct 2014, 09:20 AM
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.




0
Iliana Dyankova
Telerik team
answered on 07 Oct 2014, 07:12 AM
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!
 
0
Dirk
Top achievements
Rank 1
answered on 15 Apr 2016, 10:07 AM

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

0
Dirk
Top achievements
Rank 1
answered on 15 Apr 2016, 10:11 AM
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.
0
Saranya
Top achievements
Rank 1
answered on 27 Apr 2016, 11:34 PM
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?
0
Iliana Dyankova
Telerik team
answered on 29 Apr 2016, 12:58 PM
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!
 
Tags
Grid
Asked by
NaveRonen
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Igor Stanek
Top achievements
Rank 1
Dirk
Top achievements
Rank 1
Saranya
Top achievements
Rank 1
Share this question
or