This is a migrated thread and some comments may be shown as answers.

Filter on Selected Items with GridClientSelectColumn??

14 Answers 435 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marty
Top achievements
Rank 1
Marty asked on 05 Mar 2009, 08:53 PM

Hello,

I'm using the following to provide checkboxes for row selection in one of my grids:

<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn">  
    <HeaderStyle Width="20px"></HeaderStyle> 
</telerik:GridClientSelectColumn> 

I'd like to be able to filter the contents of the grid based upon whether or not a row is selected.  E.g. display all rows, only those selected, or only those not selected.  I'm figuring it's not as simple as just setting AllowFilteringByColumn="true", but would like to know if it's possible through built-in means or if I have to do it through some custom code.  As simple as this seems, I couldn't find anything about it in the forums.

Currently, when setting AllowFilteringByColumn to true, I get the filter boxes on all of my other columns, but nothing on this one as for filter options.

I'm using Q32008 .NET 3.5 version of the controls.

Any help is greatly appreciated.
Thanks in advance,
Marty

14 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Mar 2009, 11:06 AM
Hello Marty,

Try the following code snippet for achieving the functionanlity.

ASPX:
<FilterTemplate> 
    <asp:DropDownList ID="DropDownList1"  AutoPostBack="true" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged" > 
        <asp:ListItem Text="Selected"></asp:ListItem> 
        <asp:ListItem Text="Not Selected"></asp:ListItem> 
        <asp:ListItem Text="All"></asp:ListItem> 
    </asp:DropDownList> 
</FilterTemplate> 

CS:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)   
{   
    DropDownList dropdown = (DropDownList)sender;   
    if (dropdown.SelectedValue == "Selected")   
    {   
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)   
        {   
           // CheckBox chk = (CheckBox)item["Select"].Controls[0];   
            if (!item.Selected)   
            {   
                item.Display = false;   
            }   
        }   
    }   
    else if (dropdown.SelectedValue == "Not Selected")   
    {   
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)   
        {   
           // CheckBox chk = (CheckBox)item["Select"].Controls[0];   
            if (item.Selected)   
            {   
                item.Display = false;   
            }   
        }   
    }   
    else  
    {   
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)   
        {                   
            item.Display = true;   
        }   
    }   
}  

Thanks,
Princy.
0
Marty
Top achievements
Rank 1
answered on 06 Mar 2009, 12:30 PM
Thank you for this code.  I believe it will work, but currently the grid still loads with no filter in the column w/the checkbox.

I've pasted the entire grid, with your code incorporated below, just in case I have something else wrong causing it not to show.  The grid is embedded in a table, inside of a RadPanelBar, if that matters.  Is there maybe an option I need to set to true, to allow custom filter templates?
<telerik:RadGrid OnDetailTableDataBind="GrdSysApps_DetailTableDataBind" ID="GrdSysApps" 
    runat="server" OnNeedDataSource="GrdSysApps_OnNeedDataSource" AllowMultiRowSelection="True" 
    ClientSettings-Scrolling-AllowScroll="true" AutoGenerateColumns="False" Width="99%" 
    ClientSettings-Scrolling-ScrollHeight="125" GridLines="None" ShowGroupPanel="true" 
    ClientSettings-Scrolling-SaveScrollPosition="true" ClientSettings-Scrolling-UseStaticHeaders="true" 
    AllowFilteringByColumn="true">  
    <MasterTableView DataKeyNames="SystemApplicationID">  
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
        </ExpandCollapseColumn> 
        <Columns> 
            <telerik:GridBoundColumn DataField="SystemApplicationID" EmptyDataText="&amp;nbsp;" 
                UniqueName="column" Visible="False">  
            </telerik:GridBoundColumn> 
            <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" FilterControlWidth="50px">  
                <HeaderStyle Width="20px"></HeaderStyle> 
                <FilterTemplate> 
                    <asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">  
                        <asp:ListItem Text="Selected"></asp:ListItem> 
                        <asp:ListItem Text="Not Selected"></asp:ListItem> 
                        <asp:ListItem Text="All"></asp:ListItem> 
                    </asp:DropDownList> 
                </FilterTemplate> 
            </telerik:GridClientSelectColumn> 
            <telerik:GridBoundColumn DataField="Name" EmptyDataText="&amp;nbsp;" 
                HeaderText="Name" UniqueName="column2">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Description" EmptyDataText="&amp;nbsp;" HeaderText="Description" 
                UniqueName="column3">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="ManagerDel" EmptyDataText="&amp;nbsp;" HeaderText="Mgr Approver" 
                UniqueName="column5">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="DirectorDel" EmptyDataText="&amp;nbsp;" HeaderText="Dir Approver" 
                UniqueName="column9">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Director2Del" EmptyDataText="&amp;nbsp;" HeaderText="Dir2 Approver" 
                UniqueName="column6">  
            </telerik:GridBoundColumn> 
        </Columns> 
        <DetailTables> 
            <telerik:GridTableView DataKeyNames="SystemApplicationID" HierarchyLoadMode="ServerOnDemand" 
                AllowSorting="false">  
                <ParentTableRelation> 
                    <telerik:GridRelationFields MasterKeyField="SystemApplicationID" DetailKeyField="SystemApplicationID" /> 
                </ParentTableRelation> 
                <Columns> 
                    <telerik:GridBoundColumn HeaderText="Default System Manager" HeaderButtonType="TextButton" 
                        DataField="Manager">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn HeaderText="Default System Director" HeaderButtonType="TextButton" 
                        DataField="Director">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn HeaderText="Default System 2nd Director" HeaderButtonType="TextButton" 
                        DataField="Director2">  
                    </telerik:GridBoundColumn> 
                </Columns> 
            </telerik:GridTableView> 
        </DetailTables> 
    </MasterTableView> 
    <ClientSettings> 
        <Selecting AllowRowSelect="True" /> 
    </ClientSettings> 
    <FilterMenu EnableTheming="True">  
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    </FilterMenu> 
</telerik:RadGrid> 
0
Accepted
Iana Tsolova
Telerik team
answered on 09 Mar 2009, 10:29 AM
Hi Marty,

Indeed, GridClientSelectColumn does not support filtering, and that is why your filter template is not displayed.
However in order to have filterable ClientSelectColumn, you could create your custom column and which inherits from GridClientSelectColumn and override the SupportsFiltering method. Note that, you will need to handle the new column filtering by yourself then.

Check it out and let me know if this works for you.
 
Regards,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marty
Top achievements
Rank 1
answered on 09 Mar 2009, 05:04 PM
Lana,

Once implmented, this is working perfectly, exactly as I need it to.  Thank you for the example and detailed description.

Marty
0
Marty
Top achievements
Rank 1
answered on 09 Mar 2009, 07:08 PM

Lana/Anybody,

I'd like to ask one more question re: this grid.  I need to access the DropDownList embedded in my filtertemplate from code-behind from outside of the event handlers for it.  I've tried every way I know of to get a reference to it, but none seem to work.  So, if I have a reference to the grid, how do I go about getting a reference to the control in my FilterTemplate (cboGrdSysAppsFilter) in C# code-behind?  Grid as follows:

<telerik:RadGrid OnDetailTableDataBind="GrdSysApps_DetailTableDataBind" ID="GrdSysApps" 
    runat="server" OnNeedDataSource="GrdSysApps_OnNeedDataSource" AllowMultiRowSelection="True" 
    ClientSettings-Scrolling-AllowScroll="true" AutoGenerateColumns="False" Width="99%" 
    ClientSettings-Scrolling-ScrollHeight="150" GridLines="None" ShowGroupPanel="true" 
    ClientSettings-Scrolling-SaveScrollPosition="true" ClientSettings-Scrolling-UseStaticHeaders="true" 
    AllowFilteringByColumn="true" AllowSorting="true" ClientSettings-AllowColumnsReorder = "false">  
    <MasterTableView DataKeyNames="SystemApplicationID" ClientDataKeyNames="SystemApplicationID" > 
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
        </ExpandCollapseColumn> 
        <Columns> 
            <telerik:GridBoundColumn DataField="SystemApplicationID" EmptyDataText="&amp;nbsp;" 
                UniqueName="column" Visible="False">  
            </telerik:GridBoundColumn> 
            <custom:CustomClientSelectColumn UniqueName="SelectedRows">  
                <filtertemplate> 
                    <asp:DropDownList Font-Size="X-Small" ID="cboGrdSysAppsFilter" AutoPostBack="true" runat="server" OnSelectedIndexChanged="cboSelected_SelectedIndexChanged">  
                        <asp:ListItem>All</asp:ListItem> 
                        <asp:ListItem>Selected</asp:ListItem> 
                        <asp:ListItem>Not Selected</asp:ListItem> 
                    </asp:DropDownList> 
                </filtertemplate> 
            </custom:CustomClientSelectColumn> 
            <telerik:GridBoundColumn DataField="Name" EmptyDataText="&amp;nbsp;" HeaderText="Name" 
                UniqueName="column2">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Description" EmptyDataText="&amp;nbsp;" HeaderText="Description" 
                UniqueName="column3">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="ManagerDel" EmptyDataText="&amp;nbsp;" HeaderText="Mgr Approver" 
                UniqueName="column5">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="DirectorDel" EmptyDataText="&amp;nbsp;" HeaderText="Dir Approver" 
                UniqueName="column9">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Director2Del" EmptyDataText="&amp;nbsp;" HeaderText="Dir2 Approver" 
                UniqueName="column6">  
            </telerik:GridBoundColumn> 
        </Columns> 
        <DetailTables> 
            <telerik:GridTableView DataKeyNames="SystemApplicationID" HierarchyLoadMode="ServerOnDemand" 
                AllowSorting="false" AllowFilteringByColumn="false" Name="OriginalOwners">  
                <ParentTableRelation> 
                    <telerik:GridRelationFields MasterKeyField="SystemApplicationID" DetailKeyField="SystemApplicationID" /> 
                </ParentTableRelation> 
                <Columns> 
                    <telerik:GridBoundColumn HeaderText="Default System Manager" HeaderButtonType="TextButton" 
                        DataField="Manager">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn HeaderText="Default System Director" HeaderButtonType="TextButton" 
                        DataField="Director">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn HeaderText="Default System 2nd Director" HeaderButtonType="TextButton" 
                        DataField="Director2">  
                    </telerik:GridBoundColumn> 
                </Columns> 
            </telerik:GridTableView> 
        </DetailTables> 
    </MasterTableView> 
    <ClientSettings AllowDragToGroup="true">  
        <Selecting AllowRowSelect="true" /> 
        <ClientEvents OnRowSelected="GrdSysApps_RowSelected" OnRowDeselected="GrdSysApps_RowDeselected" 
                        OnRowCreated="GrdSysApps_RowCreated" OnCommand="RaiseCommand"/>  
    </ClientSettings> 
    <FilterMenu EnableTheming="True">  
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    </FilterMenu> 
</telerik:RadGrid> 

 

Thanks,

Marty

0
Iana Tsolova
Telerik team
answered on 10 Mar 2009, 03:17 PM
Hi Marty,

You could access the DropDownList through the grid FilteringItem. This could be on ItemCreated/ItemDataBound grid events on in other event by getting GridFilteringItem as below:

<asp:Button ID="Button1" runat="server" Text="Get Filter DropDownList value"   
    OnClick="Button1_Click" /> 
protected void Button1_Click(object sender, EventArgs e)  
{  
    GridItem[] filterItems = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem);  
    foreach (GridItem item in filterItems)  
    {  
        DropDownList filterDropDwnList = (item as GridFilteringItem)["SelectedRows"].FindControl("cboGrdSysAppsFilter"as DropDownList;  
        this.form1.Controls.Add(new LiteralControl(filterDropDwnList.SelectedValue));  
    }  

Find more about accessing grid cells and rows here.

Give it a try and let me know how it goes.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marty
Top achievements
Rank 1
answered on 11 Mar 2009, 02:51 PM
Lana,

I used a slight variation of that, and it works.  Thank you very much for your time and useful advice.

The following code acheived my goal:
 foreach (GridFilteringItem filterItem in grdSysAppsRef.MasterTableView.GetItems(GridItemType.FilteringItem))  
        {  
            DropDownList combo = (DropDownList)filterItem.FindControl("cboGrdSysAppsFilter"); 

Marty
0
Marty
Top achievements
Rank 1
answered on 11 Mar 2009, 04:07 PM
Lana,

I have one more question about this.

Since I'm using a custom FilterTemplate as described above, I'm having a hard time figuring out how to make the other filters on the other grid columns recognize my FilterTeplate.  

I'm trying to make sure that the whatever setting I've set on my custom filter is retained, and considered, when doing sorting/grouping/filtering on the other columns.  I figure I can use a Session variable to store its selected value whenever changed, however, at what point in the Event lifecycle will all the data be available for me to parse through all of my items to apply my custom filter?  Also, how would I make sure that when I've filtered based on my custom filter, that applying another filter will only consider the currently visible items?  Would it involve the PreRender event?  I've tried using it, but the results are not quite right.

I hope this makes sense, and thank you again.

Marty
0
Iana Tsolova
Telerik team
answered on 13 Mar 2009, 11:22 AM
Hello Marty,

Indeed, the desired behavior is the default behavior of RadGrid. When you filter by any column, then filtering on other column filters only record returned after the first filtering.

Please check out this demo for getting better idea on how the filtering with FilterTemplates work.

All the best,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marty
Top achievements
Rank 1
answered on 13 Mar 2009, 06:22 PM
Thanks Lana, for the response.  I actually handled this a bit differently.  I decided to handle this custom filter on the client-side, rather than on the server side.  I've been able to successfully find what I needed through other examples and the help file.

I'd like to suggest however, that perhaps for a future release, that something like this be integrated with the clientSelectColumn.  I've spent the entire week figuring out a way to implement filtering on this column (only for selected/not selected/all items) and finally got it but don't think that I'm the only person that might find such functionality useful.

Thanks again.
0
Iana Tsolova
Telerik team
answered on 16 Mar 2009, 12:29 PM
Hello Marty,

I am happy to hear you found a solution for your case.

And yes, I will forward your suggestion for implementation or at least will add new code library implementing filtering for GridClientSelectColumn.

If any issues arise, do not hesitate to type again.

Greetings,
Iana
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Gary
Top achievements
Rank 1
answered on 10 May 2010, 09:54 PM
Ok I used the example and in Desgin view I see the filter box, but when i run it I Get

Unknown server tag 'custom:MyClientSelectColumn'.

Yes I have it registerd

<%

@ Register Namespace="EA_Project" TagPrefix="custom" %>

 


 

<custom:MyClientSelectColumn>

 

 

<filtertemplate>

 

 

<asp:DropDownList ID="dropDownList" runat="server">

 

 

<asp:ListItem>Selected</asp:ListItem>

 

 

<asp:ListItem>Not Selected</asp:ListItem>

 

 

</asp:DropDownList>

 

 

</filtertemplate>

 

 

</custom:MyClientSelectColumn>

 


Please when you give examples, make sure all the code is in the project and it runs,  Your example does not work either for me.

Thanks for your help.


0
Tommy
Top achievements
Rank 1
answered on 19 Nov 2014, 07:25 PM
This demo doesn't work. It looks like the code to do the custom filtering was left out
0
Maria Ilieva
Telerik team
answered on 24 Nov 2014, 12:33 PM
Hi Tommy,

If you are discussing this online demo, I have to say that it behaves properly on my end and presents the correct approach for adding FilterTemplate to RadGrid columns.

Please let me know what the exact issue you are facing is, and why you are finding the demo unpleasant?

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Marty
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Marty
Top achievements
Rank 1
Iana Tsolova
Telerik team
Gary
Top achievements
Rank 1
Tommy
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or