2

In their documentation Telerik says that there is a way to disable sorting for specific column by using AllowSorting property. I'm looking at Telerik.Web.UI.GridColumn members and there is no AllowSorting property. There is a Sortable property but its protected and has to be overriden. So what do I use to turn off sorting for specific column?

There is a AllowSorting property on GridBoundColumn but in this case I'm using GridTemplateColumn. Is there a way to turn off sorting on GridTemplateColumn?

dev.e.loper
  • 35,446
  • 76
  • 161
  • 247

6 Answers6

6

The AllowSorting attribute is available from the source/markup view in Visual Studio. For example (simplified):

    <tr:RadGrid>
    <MasterTableView>
        <Columns>
            <tr:GridBoundColumn DataField="field" HeaderText="Description" 
                 AllowSorting="false" />
        </Columns>
    </MasterTableView>
    </tr:RadGrid>

I don't know if this works for you? I haven't instantiated my grids from the code-behind files yet, so if that's what you are doing, I can't easily help you. But the above works for me.


EDIT:

Ah it was not clear from the original question, that you were using the GridTemplate column. As you are now using the SortExpression-property, doesn't using the same attribute in the markup work for you? So:

    <tr:RadGrid>
    <MasterTableView>
        <Columns>
            <tr:GridTemplateColumn HeaderText="Description" DataField="field" 
                SortExpression="">
                <!-- template here etc. -->
            </tr:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    </tr:RadGrid>
pyrocumulus
  • 9,072
  • 2
  • 43
  • 53
  • Yes, there is a AllowSorting property on GridBoundColumn but in this case I'm using GridTemplateColumn. Is there a way to turn off sorting on GridTemplateColumn? – dev.e.loper Apr 28 '09 at 15:27
4

Okay, I got the desired effect, I turned off sorting by setting GridTemplateColumn's SortingExpression property to blank.

Grid.Columns.FindByUniqueName("Type").SortExpression = string.Empty;

This looks like a hack. Why isn't there an explicit property to turn off sorting? Oh well. This works.

If you know a better way, let me know.

Thanks.

dev.e.loper
  • 35,446
  • 76
  • 161
  • 247
  • 1
    I have edited an extra sample in my original post. It's based on what you are doing here. Does that work for you? – pyrocumulus Apr 28 '09 at 17:28
  • Yes. Basically we are doing same thing. Only I'm doing it in code-behind and you are doing it declaritevely. – dev.e.loper Apr 28 '09 at 18:20
  • Dont know why they just didnt provide the AllowSorting, but dont think its a hack, at least for client side binding this totally disables the sort behaviour. – Sameer Alibhai Apr 13 '10 at 20:56
3

Telerik now has a new property called HeaderButtonType (exists on a template column too!) which can be set to "None" to render a label instead of a linkbutton for the column header text.

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
breenbob
  • 31
  • 1
1

As stated in the Telerik Docs:

In case you want to disable sorting for a particular column only, you can configure column's IsSortable property to False:

<telerik:GridViewColumn IsSortable="False" />
anhoppe
  • 4,287
  • 3
  • 46
  • 58
0

You could always supply your own headertemplate with a label as the header instead of a link button if you are using a GridTemplateColumn. A we bit extra work but this works fine. If you are going to disable sorting for all your GridTemplateColumns then your "hack" would be best.

infocyde
  • 4,140
  • 2
  • 25
  • 36
0

Here's an example showing how to disable sorting for a specific column.

Note the AllowSorting property at the Grid level (for all columns).

Then, in the Columns collection, note how it is turned off for that specific column.

<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True">
    <HeaderContextMenu>
        <CollapseAnimation Duration="200" Type="OutQuint" />
    </HeaderContextMenu>
    <MasterTableView>
        <RowIndicatorColumn>
            <HeaderStyle Width="20px" />
        </RowIndicatorColumn>
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px" />
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn AllowSorting="False" UniqueName="column">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <FilterMenu>
        <CollapseAnimation Duration="200" Type="OutQuint" />
    </FilterMenu>
</telerik:RadGrid>

For TemplateColumns, I would try turning off Sorting at the grid level and simply enable it on the columns needed. That way, you won't have to do anything for the TemplateColumn since it will be disabled by default.

Mark Sherretta
  • 10,160
  • 4
  • 37
  • 42
  • Yes, there is a AllowSorting property on GridBoundColumn but in this case I'm using GridTemplateColumn. Is there a way to turn off sorting on GridTemplateColumn? – dev.e.loper Apr 28 '09 at 15:27
  • Yeah that would work but there is no enable/disable sorting property for GridTemplateColumn. – dev.e.loper Apr 28 '09 at 15:37