Single column sorting - still able to have other columns sorted?

3 posts, 1 answers
  1. Uwe
    Uwe avatar
    10 posts
    Member since:
    Mar 2008

    Posted 13 Nov 2012 Link to this post

    Dear support

    Having a grid with multiple columns that is configured to single column sorting mode, I discovered that as soon as the grid is sorted by one column, the other columns get completely unordered.

    Please see the attached image for an example

    What I want to achieve is that even if the user actively sorts by one column (through clicking on the header), the other columns still have some meaningful (e.g. ascending) order.

    So my question is:

    Is it possible to tell a grid with single sort and client-side sorting to sort the other columns, too?


    (Update: The original image was misleading, I added a better one)
  2. Answer
    Iliana Nikolova
    Iliana Nikolova avatar
    2622 posts

    Posted 16 Nov 2012 Link to this post

    Hi Uwe,

    I am afraid there is no built-in configuration option in Kendo UI Grid (except multiple sorting) for getting the described behavior and in order to achieve it you need to implement your own sorting. For this purpose the Grid's DataSource sort() method can be used.

    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. Uwe
    Uwe avatar
    10 posts
    Member since:
    Mar 2008

    Posted 16 Nov 2012 Link to this post

    In case anyone is interested, this is the code I've used to solve this for me, based on Iliana's answer:
    // Save the reference to the original sort function.
    grid.dataSource.originalSort = grid.dataSource.sort;
    // Replace the original sort function.
    grid.dataSource.sort = function() {
        // If a column is about to be sorted, this function gets called.
        if (arguments.length > 0) {
            // If not sorted by name, add name as the second sort field.
            var ar = arguments[0];
            if (ar[0].field != "MyNameColumn") {
                ar[ar.length] = { dir: "asc", field: "MyNameColumn" };
                arguments[0] = ar;
        // Call the original sort function.
        var result = grid.dataSource.originalSort.apply(this, arguments);
        return result;
    I also used some code from this Kendo forum posting.
Back to Top