This is a migrated thread and some comments may be shown as answers.
Implementing filtering for column containing custom formatted text.
4 Answers 46 Views
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 02 Jun 2011, 10:38 PM
Hi there,

I've a simple RadGrid which is bound through an objectDataSource. I've a couple of columns which are bound, using DataField attribute, to the properties of type returned by ObjectDataSource bound method.
<telerik:RadGrid ID="RGTasks" AllowPaging="True" runat="server"
                AutoGenerateColumns="False" GridLines="None" CellSpacing="0"
                DataSourceID="ObjectDataSource1" Skin="Outlook" PageSize="10"
                style="width:100%; height:100%;" onitemdatabound="RGTasks_ItemDataBound"
                AllowFilteringByColumn="true" AllowSorting="true"
                onitemcommand="RGTasks_ItemCommand">
            <MasterTableView DataKeyNames="RuleScheduleKey" AutoGenerateColumns="false" CommandItemDisplay="Top"
                EditMode="EditForms" AllowAutomaticUpdates="true" AllowAutomaticInserts="false"
                AllowFilteringByColumn="true" >
                <EditFormSettings EditFormType="WebUserControl" UserControlName="../Controls/EditRule.ascx" />
                <CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="Add Task"></CommandItemSettings>
                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
                <AlternatingItemStyle BackColor="#EDF1FF" />
                <Columns>
                    <telerik:GridBoundColumn FilterControlAltText="Filter column2 column"
                        UniqueName="column2" DataField="RuleScheduleKey" HeaderText="Task"
                        HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center"
                         AllowFiltering="false">
                        <HeaderStyle HorizontalAlign="Center" Font-Bold="True"></HeaderStyle>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn FilterControlAltText="Filter column1 column"
                        UniqueName="colRule"  DataField="RuleKey" HeaderText="Rule"
                        HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center"
                        CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true">
                        <HeaderStyle HorizontalAlign="Center" Font-Bold="True"></HeaderStyle>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ScheduleKey" HeaderText="Schedule" UniqueName="ScheduleKey"
                        FilterControlAltText="Filter column6 column" AllowFiltering="false">
                        <HeaderStyle Font-Bold="True" />
                    </telerik:GridBoundColumn>
                    <telerik:GridDateTimeColumn FilterControlAltText="Filter column5 column"
                        UniqueName="column5" DataField="NextRunTimestamp" HeaderText="Next Run" ItemStyle-Width="10%"
                        HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center"
                        ReadOnly="true"  AllowFiltering="false">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                        <ItemStyle Width="10%" />
                    </telerik:GridDateTimeColumn>
                    <telerik:GridDateTimeColumn DataField="LastRunTimestamp"
                        FilterControlAltText="Filter column column" HeaderText="Last Run"
                        UniqueName="column" AllowFiltering="false">
                        <HeaderStyle Font-Bold="True" />
                    </telerik:GridDateTimeColumn>
                    <telerik:GridBoundColumn FilterControlAltText="Filter column4 column"
                        UniqueName="column4" DataField="LastRunStatus" HeaderText="Last Run Status"
                        HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center"
                        CurrentFilterFunction="Contains" ShowFilterIcon="false">
                        <HeaderStyle HorizontalAlign="Center" Font-Bold="True"></HeaderStyle>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn FilterControlAltText="Filter column3 column"
                        UniqueName="column3" DataField="CreatedById" HeaderText="Created By"
                        HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center"
                        ReadOnly="true" CurrentFilterFunction="StartsWith" ShowFilterIcon="false"
                        DataType="System.String" AutoPostBackOnFilter="true">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                    </telerik:GridBoundColumn>
        </Columns>
                <EditFormSettings >
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column" ></EditColumn>
                </EditFormSettings>
            </MasterTableView>
            <PagerStyle  PagerTextFormat="{0} / {1}" />
        <FilterMenu EnableImageSprites="False"></FilterMenu>
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
        </telerik:RadGrid>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                SelectMethod="GetAllRuleSchedulesByUserID"
                TypeName="DataAccessHelper"
                onselecting="ObjectDataSource1_Selecting"
                DataObjectTypeName="Datasets.RuleSchedule">
                <SelectParameters>
                    <asp:Parameter Name="userID" Type="String" />
                    <asp:SessionParameter SessionField="IsUserAdmin" Name="isAdmin" Type="Boolean" DefaultValue="false" />
                </SelectParameters>
            </asp:ObjectDataSource>


While the data that is being displayed on the grid is formatted in the backend using the ItemDataBound 
method.

Code behind
protected void RGTasks_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if ((e.Item.ItemType == Telerik.Web.UI.GridItemType.Item) ||
            (e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem))
    {
        try
        {
            RuleSchedule rs = new RuleSchedule();
            rs = (RuleSchedule)e.Item.DataItem;
            BusinessRule br = DataAccessHelper.GetBusinessRule(rs.RuleKey);
            if (!string.IsNullOrEmpty(br.Name))
            {
                e.Item.Cells[5].Text = "[" + e.Item.Cells[5].Text + "] " + br.Name;
            }
            Schedule sc = DataAccessHelper.GetSchedule(rs.ScheduleKey);
            if (!string.IsNullOrEmpty(sc.RecurrenceTypeCd))
            {
                e.Item.Cells[6].Text = "[" + e.Item.Cells[6].Text + "] " + sc.RecurrenceTypeCd;
            }
        }
        catch
        {
        }
    }
  
}


I would like to let users filter the displayed text in the formatted columns instead of the DataField.
ie. if the DataField value was say "14" while the displayed text post formatting is "[14] BiWeekly"
I would like to display the row if user types "week" in the filter control.

Any suggestions or pointers will be appreciated.

Thanks in advance.

Regards,

4 Answers, 1 is accepted

Sort by
0
Ron
Top achievements
Rank 1
answered on 06 Jun 2011, 03:31 PM
Could anyone provide a pointer or a suggestion to handle this scenario!
0
Iana Tsolova
Telerik team
answered on 08 Jun 2011, 09:59 AM
Hi Rohit,

To achieve your goal, you should either implement custom filtering. Or add another column in the grid which contains the formatted data.

All the best,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Ron
Top achievements
Rank 1
answered on 08 Jun 2011, 04:51 PM
Iana,

Thank you for your reply.

I'm not sure I follow you on the second suggestion. I'm not aware of which property of a non-bound cell, the filter function access but it doesnt seem to be 'Text'. In the ItemDataBound method above, I've assigning the formatted text to cell's 'Text' property. As per your suggestion, I extended the same functionality to assign the formatted text to the cell's 'Text' of a new column, but to no-avail. Am I missing something here?

As for the first suggestion, could you kindly provide me with a link to a resource? Would I need to modify my DataAccess to handle filtering as I'd to do for sorting.

Once again, many thanks for your reply.
Regards.
0
Iana Tsolova
Telerik team
answered on 09 Jun 2011, 08:01 AM
Hello Rohit,

When filtering is applied to RadGrid, RadGrid filters the datasource to which it is bound. It uses the DataField to build the filter expression and filter the records in the datasource. So if you want the grid to be filtered by the formatted text, you should have a column in the grid datasource which values are the formatted text. Then add a column to the grid which is bound to the column with the formatted text in the grid datasource.

All the best,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Ron
Top achievements
Rank 1
Answers by
Ron
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or