简体   繁体   中英

Kendo UI Grid - Sort by Descending Before Ascending

I've read through every online post I could find about about sorting with the Kendo Grid. Basically I'm trying to find a way to sort by descending first and then ascending after. I know how to set a default sort as descending when the grid loads, but I need this to happen any time a field is sorted. If there is no sort, it should sort by descending first.

  sortable: {
            allowUnsort: false
            SortByDescendingFirst: true <== Something like this
        },

I don't think there's an option to define that - you can try something like this (this is for Q1 2014, in older versions you can do the same but you have to modify kendo.ui.Sortable.fn._click instead):

kendo.ui.Sorter.fn._click = function (originalFn) {
    return function (e) {
        var element = this.element,
            dir = element.attr(kendo.attr("dir"));

        if (!dir) element.attr(kendo.attr("dir"), "asc");
        if (dir === "desc") element.attr(kendo.attr("dir"), "");
        if (dir === "asc") element.attr(kendo.attr("dir"), "desc");

        originalFn.call(this, e);
    };
}(kendo.ui.Sorter.fn._click);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM