# Sorting

By default, the sorting functionality of the Telerik UI Grid for ASP.NET MVC is disabled.

## Getting Started

To control the sorting in the Grid, use the [`Sortable`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/gridbuilder#sortable) option. as a result, the default [single-column sorting](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/sorting#single-column-sorting) functionality will be applied.

```Razor HtmlHelper
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
        .Name("Grid")
        .Sortable()
        ...
    )
```

> Only columns that are [bound to a field](https://docs.telerik.com/kendo-ui/api/ui/grid/configuration/columns.field) can be sortable. To enable sorting on a column bound to an object, [bind the column to a field of that object](https://docs.telerik.com/aspnet-core/knowledge-base/grid-enable-operations-for-object-column).

## Sort Modes

The Grid supports the following sort modes:

* [Single-column sort mode](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/sorting#single-column-sorting)
* [Multi-column sort mode](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/sorting#multi-column-sorting)
* [Mixed-column sort mode](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/sorting#mixed-column-sorting)

### Single-Column Sorting

By default, the Grid applies single-column sorting when the `Sortable()` method is enabled. Alternatively, you can configure single-column sort mode by setting the [`SortMode`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/gridsortsettingsbuilder#sortmodekendomvcuigridsortmode).

```Razor HtmlHelper
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
        .Name("Grid")
        .Sortable(sortable => sortable
            .SortMode(GridSortMode.SingleColumn))
        ...
    )
```

### Multi-Column Sorting

To allow the multi-column sorting, set the [`SortMode()`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/gridsortsettingsbuilder#sortmodekendomvcuigridsortmode) method to `MultipleColumn`.

```Razor HtmlHelper
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
        .Name("Grid")
        .Sortable(sortable => sortable
            .SortMode(GridSortMode.MultipleColumn))
        ...
    )
```

You can also specify if the columns can be unsorted by setting the [`AllowUnsort`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/gridboundcolumnsortablebuilder#allowunsortsystemboolean) property to `true` or `false`. for a runnable example, refer to the [demo on sorting in the grid](https://demos.telerik.com/aspnet-mvc/grid/sorting).

With the multi-column sorting you can configure the Grid to display the sort indexes in the header by enabling the [`ShowIndexes`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/gridsortsettingsbuilder#showindexessystemboolean) property.

```Razor HtmlHelper
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
        .Name("Grid")
        .Sortable(sortable => sortable
            .AllowUnsort(true)
            .SortMode(GridSortMode.MultipleColumn)
            .ShowIndexes(true))
        ...
    )
```

### Mixed-Column Sorting

The mixed sorting allows you to [single-sort](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/sorting#single-column-sorting) columns by clicking their header and [multi-sort](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/sorting#multi-column-sorting) columns by holding the `CTRL` key and clicking the columns header. A single-click (without holding the `CTRL` key) on any column un-sorts the currently sorted columns and applies single-sorting to the clicked column.

To enable the mixed-column sorting, set the [`SortMode()`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/gridsortsettingsbuilder#sortmodekendomvcuigridsortmode) option to `Mixed`.

```Razor HtmlHelper
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
        .Name("Grid")
        .Sortable(sortable => sortable
            .SortMode(GridSortMode.Mixed))
        ...
    )
```

## Defining Field Type

If you want to sort a column as a different type than the original one in the database (for example, decimal<->string and vice versa), you can use the following approach:

```Razor HtmlHelper
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
        .Name("Grid")
        .Sortable()
        ...
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(m =>
            {
                m.Id("OrderID");
                m.Field("Freight", typeof(string));
            })
            .ServerOperation(false)
            .PageSize(20)
            .Read(read => read.Action("Orders_Read", "Grid"))
        )
    )
```

## See Also

* [Sorting by the Grid HtmlHelper for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/grid/sorting)
* [Knowledge Base Section](https://www.telerik.com/aspnet-mvc/documentation/knowledge-base)
* [Server-Side API](https://www.telerik.com/aspnet-mvc/documentation/api/grid)
