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

Fire "Sort" command on column header click

4 Answers 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Crescent
Top achievements
Rank 1
Crescent asked on 03 Dec 2008, 07:15 PM
I would like to allow the user to be able to click anywhere in the column header to sort the grid by that column. RadGrid currently seems to only support clicking on the header Text. Are there any documented demos that show how to do this?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Dec 2008, 06:37 AM
Hi Crescent,

Try the following code snippet to achieve the desired scenario.

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> 


Regards
Shinu.
0
Crescent
Top achievements
Rank 1
answered on 16 Dec 2008, 08:54 PM
Your example breaks the original functionality: clicking on the header text now does not flip the sort. I guess you don't test code snippets you post.
0
Shinu
Top achievements
Rank 2
answered on 17 Dec 2008, 04:31 AM
Hi Crescent,

The above code is not breaking the original functionality on my end. Sorting is working well on clicking the header text as well as the Column header. I am not sure about what is happening on your end. Which version of the Grid are you using? Mine is RadGrid for asp.net AJAX(2008.3.1125.20).

Shinu
0
Crescent
Top achievements
Rank 1
answered on 17 Dec 2008, 03:36 PM
Yep. Broken. In two projects I tried (with different data binding semantics) one didn't flip the sort, and the other fired the sort twice. I suspect the latter is more common. Try yours again using firebug. You'll see TWO data requests going out, for ONE header text click.

I'm using 2008.3.1105.35
Tags
Grid
Asked by
Crescent
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Crescent
Top achievements
Rank 1
Share this question
or