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

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

2 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Uwe
Top achievements
Rank 1
Uwe asked on 13 Nov 2012, 09:28 AM
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?

Thanks
Uwe

(Update: The original image was misleading, I added a better one)

2 Answers, 1 is accepted

Sort by
0
Accepted
Iliana Dyankova
Telerik team
answered on 16 Nov 2012, 08:48 AM
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.

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
Uwe
Top achievements
Rank 1
answered on 16 Nov 2012, 11:14 AM
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.
Tags
Grid
Asked by
Uwe
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Uwe
Top achievements
Rank 1
Share this question
or