Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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>

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.

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.

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.

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" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top