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

Show sorting indicators, but not allow sorting

6 Answers 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex Occhipinti
Top achievements
Rank 1
Alex Occhipinti asked on 03 Feb 2010, 04:25 AM
I am setting the sort order in the code behind (programatically) and I would like to have the sorting indicators displayed while not allowing the user the ability to change the sort order.

By setting the AllowSorting = true the indicators will show correctly, however, the user can then change the sort order.

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Feb 2010, 10:45 AM
Hello Alex,

I suppose you want to disable sorting if the header text or the sort icon is clicked for a particular column. If so, try the following example and see if it helps meet your requirement:
c#:
  protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if(e.CommandName == RadGrid.SortCommandName) 
        { 
            if (e.CommandSource is WebControl || e.CommandSource is LinkButton) 
            { 
                e.Canceled = true
            } 
        } 
    } 

Thanks
Princy.
0
Alex Occhipinti
Top achievements
Rank 1
answered on 03 Feb 2010, 01:05 PM
Well, I would prefer if clicking on any column would be disabled.  That is, not even creating the event so that the user would be able to mouse over the column header and not even think there's a possibility to change the sort order.
0
Princy
Top achievements
Rank 2
answered on 04 Feb 2010, 10:29 AM
Hi,

A suggestion would be to clear the controls in the Header cell and then add a label to the controls collection. This way you can avoid the hand cursor and the postback in the header.

C#
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.Header)) 
        { 
            foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
            { 
                if (item[col.UniqueName].Controls.Count != 0) 
                { 
                   if (item[col.UniqueName].Controls[0] is LinkButton) 
                    { 
                        string strtxt = ((LinkButton)item[col.UniqueName].Controls[0]).Text; 
                        item[col.UniqueName].Controls.Clear(); 
                        Label lbl = new Label(); 
                        lbl.ID = "Label" + col.UniqueName; 
                        lbl.Text = strtxt; 
                        item[col.UniqueName].Controls.Add(lbl); 
                    } 
                } 
            } 
        }  
 


Thanks,
Princy
0
Alex Occhipinti
Top achievements
Rank 1
answered on 04 Feb 2010, 01:25 PM
Yikes, that's a ton of effort that I'd care not to repeat every time I use a RadGrid.  I guess I'll just live with the the sort indicators not showing or allowing users to resort the grid.  Perhaps a property or option should be added to the grid for this case.  Maybe a ShorSortIndicators property that works along with AllowSorting.

Thanks for looking into it!
0
Remi
Top achievements
Rank 2
answered on 24 Feb 2010, 07:44 PM
Hey all,

I agree, there should be a simple properity to set in order to disable the sort functionality or change the default sort order on grid columns individual. You should be able to apply this properity in design view / the form; rather than, through code behind.

The suggestion you are making is a lot of overhead and complications the situation. People use these controls to simplify development life, not to write a bunch more code to interact with the control for common functionality.

Removing the sort on individaul columns and, or changing the default order of a particular column is something common. You might only want to change 5 out of say, 10 columns in your grid.

Please help make this simple. I'm disheartened.
0
Sebastian
Telerik team
answered on 25 Feb 2010, 09:24 AM
Hi Remi,

Each grid column has AllowSorting/AllowFiltering property with default true value. If you set it to false, you will disable the sorting or filtering for that particular column although it can be enabled for the grid itself.

How to control the sort order and modes of grid columns you can see from this topic in the documentation.

Best regards,
Sebastian
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Alex Occhipinti
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Alex Occhipinti
Top achievements
Rank 1
Remi
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or