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

Sorting on click of Grid Header.

2 Answers 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Puttu
Top achievements
Rank 1
Puttu asked on 09 Feb 2009, 01:10 PM

RADGrid sorts records only when the HeaderText of a column is clicked. I want to sort Grid data on click of the column header. Is there a way to do this?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Feb 2009, 03:49 AM
Hi Puttu,

Give a try with the following code snippet in the PreRender event of the RadGrid and see if it helps.

CS:
protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)  
        {  
            foreach (GridHeaderItem header in RadGrid1.MasterTableView.GetItems(GridItemType.Header))  
            {  
                header[col.UniqueName].Attributes.Add("OnClick""return SortColumn('"+ col.UniqueName+ "');");  
            }  
        }  
   }  

JS:
<script type="text/javascript">  
        function SortColumn(ColumnName)  
        {  
         var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();  
          masterTable.sort(ColumnName);  
        }  
        </script>  


Thanks
Shinu.




0
ww1711
Top achievements
Rank 1
answered on 18 Dec 2013, 04:22 PM
For those wondering if this works or not... YES. It does.

My issue is that while editing the header text with custom strings, the sorting disappeared. This works, though.

+1 Shinu!
Tags
Grid
Asked by
Puttu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
ww1711
Top achievements
Rank 1
Share this question
or