Telerik Extensions for ASP.NET MVC

This help topic discusses the sorting feature of Telerik Grid for ASP.NET MVC

Important

All Telerik UI components need a ScriptRegistrar component in order to output their JavaScript objects and register their JavaScript files. The ScriptRegistrar component should be defined *after* all other UI components in the page. If you create the components on the client-side and do not use the MVC extensions, you need to manually register all requried JavaScript files. For further information check this help topic (Step 4 - Register Scripts)

Sorting allows the user to sort the grid columns by clicking their header. To enable sorting use the Sortable()()()() method:

CopyView
<%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .Sortable()
%>
This would enable sorting with default configuration - all bound columns are sortable and the user can sort by only one column at the same time.

Sorting Configuration

You can customize the sorting behavior by using the Sortable(Action<(Of <<'(GridSortSettingsBuilder>)>>)) method. It allows you to do the following:
  • Enable sorting based on some condition via the Enabled(Boolean) method:
    CopyView
    <%= Html.Telerik().Grid(Model)
            .Name("Grid")
            .Sortable(sorting => sorting.Enabled((bool)ViewData["enableSorting"]))
    %>
  • Allow multiple column sorting via the SortMode(GridSortMode) method:
    CopyView
    <%= Html.Telerik().Grid(Model)
            .Name("Grid")
            .Sortable(sorting => sorting.SortMode(GridSortMode.MultipleColumn))
    %>
If you want to disable sorting for a particular column you can use the Sortable(Boolean) method:
CopyView
<%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(o => o.OrderID).Sortable(false);
        })
        .Sortable()
%>
You can also configure the initial sort order of the grid:
CopyView
<%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(o => o.OrderID).Sortable(false);
        })
        .Sortable(sorting => sorting.OrderBy(sortOrder => sortOrder.Add(o => o.OrderID)))
%>

See Also