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

Rad Grid Sorting

4 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nithya Rani
Top achievements
Rank 1
Nithya Rani asked on 15 Apr 2013, 02:04 PM
Hi,

I have implemented sorting. If my column is not sorted then i want to show an image that particular column is not sorted sorting is available for this column. if its shorted then my default behavior should happen. any one can help me in this.

Regards,
Nithya

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 16 Apr 2013, 03:55 AM
Hi,

An easy way to change the RadGrid sort arrows is to use the SortAscImageUrl and SortDescImageUrl properties, which are set per column.
More information is available in this link:
Basic Sorting(Customizing the sorting arrows)

Thanks,
Princy.
0
Nithya Rani
Top achievements
Rank 1
answered on 16 Apr 2013, 09:32 AM
Hi Princy,

My requirement is different. If my column is not sorted then i need to show the icon.

Regards,
Nithya
0
Princy
Top achievements
Rank 1
answered on 17 Apr 2013, 03:56 AM
Hi Nithya Rani,

I guess you want to add an image next to the HeaderText of a column indicating the column can be sorted and removing it on sorting. Please take a look into the following code snippet.

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem)
    {
        GridHeaderItem header = (GridHeaderItem)e.Item;
        Image img = Image();   
        img.ID = "Image1";
        img.ImageUrl = "~/Images/Sort.gif";
        header["ColumnUniqueName"].Controls.AddAt(1, img);
        if (RadGrid1.MasterTableView.SortExpressions.Count > 0 && RadGrid1.MasterTableView.SortExpressions[0].FieldName == "ColumnFieldName")
        {
            if (RadGrid1.MasterTableView.SortExpressions[0].SortOrder == GridSortOrder.Ascending || RadGrid1.MasterTableView.SortExpressions[0].SortOrder == GridSortOrder.Descending)
            {
                header["ColumnUniqueName"].Controls.Remove(img);
            }
        }
    }
}

Thanks,
Princy.
0
Nithya Rani
Top achievements
Rank 1
answered on 17 Apr 2013, 06:14 AM
Hi Princy,

Thank you its worked for me.

Regards,
Nithya
Tags
Grid
Asked by
Nithya Rani
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Nithya Rani
Top achievements
Rank 1
Share this question
or