# Customizing the Grid Column Sorting Icons

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Grid</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2023.3.1010 version</td>
 </tr>
</table>

## Description

How can I change the default sorting icons of the Grid columns?

## Solution

To set custom ascending and descending sorting icons when a specified Grid column is sorted and display a double arrow icon when the column is not sorted, follow these steps:

1. Add the following CSS style to hide the default sorting icons:

```css
#grid .k-grid-header .k-cell-inner .k-link .k-sort-icon {
    display: none;
}
```

2. Handle the `DataBound` event of the Grid that triggers each time a specified column is sorted (the sorting data operation is performed on the server (`ServerOperation(true)`).

```Razor HtmlHelper
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
    .Name("grid")
    .Sortable(sortable => sortable
        .AllowUnsort(true)
        .SortMode(GridSortMode.Mixed)
        .ShowIndexes(true))
    .Events(ev => ev.DataBound("onDataBound"))
    // other grid configuration
)
```

3. Within the `DataBound` event handler, define the desired SVG icons as explained in the [SVG Icons section in the documentation](https://docs.telerik.com/aspnet-mvc/styles-and-layout/sass-themes/svg-icons#setting-svg-icons-from-client). Then, access the currently sorted fields through the [`sort()`](https://docs.telerik.com/kendo-ui/api/data/datasource/methods/sort) method of the DataSource and append the respective icon (ascending or descending).

```javascript
<script>
function onDataBound(e) {
    let grid = this;
    let sorts = grid.dataSource.sort(); // Get the currently sorted fields.

    var nonSortableIcon = kendo.ui.icon({ icon: 'caret-alt-expand', type: 'svg' }); // Specify the desired SVG icon for the non-sorted columns.
    var descSortIcon = kendo.ui.icon({ icon: 'chevron-down', type: 'svg' }); // Specify the desired SVG icon for descending order.
    var ascSortIcon = kendo.ui.icon({ icon: 'chevron-up', type: 'svg' }); // Specify the desired SVG icon for ascending order.

    if(sorts == undefined) { // Check if the Grid is sorted initially.
        grid.thead.find("th .k-cell-inner .k-link").each(function(){  // Loop through the Grid column headers.
            $(this).append(nonSortableIcon); // Add the "nonSortableIcon " icon on all column headers.
        });
    } else {
        // Reset the sort icons.
        grid.thead.find("th .k-cell-inner .k-link").each(function(){ 
            if($(this).find("span.k-svg-i-caret-alt-expand").length == 0) {
                $(this).find("span.k-icon").remove(); // Remove the "descSortIcon"/"ascSortIcon" icon.
                $(this).append(nonSortableIcon); // Add the default icon.
            }
        });

        $.each(sorts, function(i,value) { // Loop through the sorted fields.
            let colHeader = grid.thead.find(`th[data-field='${value.field}']`); // Get the column header of the sorted column.
            if(colHeader) {
                colHeader.find(".k-link span.k-icon").remove(); // Remove the default icon.
                if(value.dir == "asc") {
                    colHeader.find(".k-link").append(ascSortIcon); //Append the custom "ascSortIcon".
                }
                if(value.dir == "desc") {
                    colHeader.find(".k-link").append(descSortIcon); //Append the custom "descSortIcon".
                }
            }
        });
    }
}
</script>
```

For a runnable example based on the code above, refer to the [REPL example on customizing the default sorting icons of the Grid columns](https://netcorerepl.telerik.com/cyYvlVFq13LOju7R01).

## More ASP.NET MVC Grid Resources

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)

* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)

* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)

* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
