SilverLight
SilverLight

Reputation: 20468

How to filter GridTemplateColumns of Telerik's RadGrid

I have two GridTemplateColumns in my RadGrid. The default filtering doesn't work for me and I want to change it.

The GridTemplateColumns are like below:

<telerik:GridTemplateColumn FilterControlAltText="Filter Online column" HeaderText="Online"
    UniqueName="Online">
    <ItemTemplate>
        <asp:CheckBox ID="chkOnline" runat="server" Checked='<%# CheckForOnline(Eval("ID")) %>'
            Enabled="False" />
    </ItemTemplate>
    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
</telerik:GridTemplateColumn>

and the other one:

<telerik:GridTemplateColumn FilterControlAltText="Filter FileSize column" HeaderText="FileSize"
    UniqueName="FileSize" Visible="False">
    <ItemTemplate>
        <asp:Label ID="lblFileSize" runat="server" Text='<%# Eval("FileSize") %>'></asp:Label>
    </ItemTemplate>
    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn FilterControlAltText="Filter FileSizeChange column" HeaderText="FileSize"
    UniqueName="FileSizeChange">
    <ItemTemplate>
        <asp:Label ID="lblFileSizeChange" runat="server" Text='<%# ChangeFileSize(Eval("FileSize")) %>'></asp:Label>
    </ItemTemplate>
    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</telerik:GridTemplateColumn>

As you can see, FileSize TemplateColumn is disabled and I am using FileSizeChange instead.

FileSize string is like (213435) -> this number shows us bytes. FileSizeChange is like (231 MB)/

How can I write filtering for both Online and FileSizeChange GridTemplateColumns?

Upvotes: 2

Views: 16883

Answers (3)

Landon Poch
Landon Poch

Reputation: 852

If you need filtering on an item template column make sure you set the following properties on the item template column:

DataField="FileSize" AllowFiltering="true" AutoPostBackOnFilter="true" DataType="System.String"

These two are optional if you want to hide the filter function icon: ShowFilterIcon="false" CurrentFilterFunction="Contains"

Also make sure you have filtering enabled on your radgrid.

Here's a good post about it: http://www.telerikschool.com/2011/11/textbox-in-gridtemplatecolumn.html

Upvotes: 4

JumpingJezza
JumpingJezza

Reputation: 5665

In order to use filtering on a Template column you need to set the DataField and add the datafield to the DataKeyNames

eg:

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowFilteringByColumn="True">
    <MasterTableView DataKeyNames="ID">
        <Columns> 
            <telerik:GridTemplateColumn DataField="ID" FilterControlAltText="Filter Online column" HeaderText="Online" UniqueName="Online">
                <ItemTemplate>
                    <asp:CheckBox ID="chkOnline" runat="server" Checked='<%# CheckForOnline(Eval("ID")) %>' Enabled="False" />
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
            </telerik:GridTemplateColumn>
...
etc, etc

Upvotes: 7

twaggs
twaggs

Reputation: 3743

Because this is an ItemTemplate that you're building manually, you will need to filter manually. See this page of the Telerik docs: http://www.telerik.com/help/aspnet-ajax/grid-operate-with-filter-expression-manually.html

Upvotes: 1

Related Questions