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

[Solved] Sortingmodes

5 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Fredrik
Top achievements
Rank 1
Fredrik asked on 16 Mar 2011, 10:33 AM
Hi.

I'm having a problem with sorting. I want my grid to always be sorted in either ascending or descending order. Is there any way to disable the grids unsorted state (so that Gridstate.Orderby is never null)?

Thank you

5 Answers, 1 is accepted

Sort by
0
Derek Trickett
Top achievements
Rank 1
answered on 28 Jul 2011, 10:07 PM
Wondering the same thing - is there any way to disable the unsorted step in the toggle cycle?  Would like to set the default sort to ascending or descending depending on requirement, then have the header toggle back and forth between ascending and descending.
0
Atanas Korchev
Telerik team
answered on 29 Jul 2011, 07:10 AM
Hello,

 No, this is not currently possible. The grid always goes through the unsorted mode. We have it logged as a feature request and will implement that in a future release (probably Q1 2012).

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

0
Bill
Top achievements
Rank 1
answered on 14 Nov 2011, 07:56 PM
Atanas, others,

There is an easy way to do this and you wont have to wait until the Q1 2012 release. 

1. Add this javascript

<script type="text/javascript">
   function onDatabinding(e) {
        var grid = $('#UserGrid').data('tGrid'); //change UserGrid to your grid name
        if (grid.orderBy == "")
        { grid.orderBy = 'LoginId-asc'; }; //change LoginId to your column name
    }
</script>

2. Subscibe to databound event and set default order for your grid

            .ClientEvents(o => o.OnDataBinding("onDatabinding"))
            .Sortable(sorting => sorting
                .OrderBy(initSortOrder => initSortOrder.Add(o => o.LoginId).Ascending())) //change LoginId to your column name

Its that easy.  Note that I am databinding ajax with operation mode server, so if your setup is different, this solution may not work.

            .DataBinding(dataBinding => dataBinding.Ajax()
                .OperationMode(GridOperationMode.Server)  //[.Server|.Client]
0
Fredrik
Top achievements
Rank 1
answered on 16 Nov 2011, 07:11 PM
Thanks. I'll try it out as soon as I get the time. I think it should be compatible with my setup.
0
Varun
Top achievements
Rank 1
answered on 24 Feb 2012, 06:33 PM
Thanks much!
Tags
Grid
Asked by
Fredrik
Top achievements
Rank 1
Answers by
Derek Trickett
Top achievements
Rank 1
Atanas Korchev
Telerik team
Bill
Top achievements
Rank 1
Fredrik
Top achievements
Rank 1
Varun
Top achievements
Rank 1
Share this question
or