dev.e.loper
dev.e.loper

Reputation: 36034

Telerik RadGrid - How to disable sorting for a Column?

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?

Upvotes: 2

Views: 19205

Answers (6)

anhoppe
anhoppe

Reputation: 4497

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" />

Upvotes: 1

breenbob
breenbob

Reputation: 31

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.

Upvotes: 3

infocyde
infocyde

Reputation: 4171

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.

Upvotes: 0

pyrocumulus
pyrocumulus

Reputation: 9290

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>

Upvotes: 6

Mark Sherretta
Mark Sherretta

Reputation: 10230

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.

Upvotes: 0

dev.e.loper
dev.e.loper

Reputation: 36034

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.

Upvotes: 4

Related Questions