Filter on Selected Items with GridClientSelectColumn??

15 posts, 1 answers
  1. Marty
    Marty avatar
    61 posts
    Member since:
    Oct 2008

    Posted 05 Mar 2009 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Mar 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marty
    Marty avatar
    61 posts
    Member since:
    Oct 2008

    Posted 06 Mar 2009 Link to this post

    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> 
  5. Answer
    Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 09 Mar 2009 Link to this post

    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.
  6. Marty
    Marty avatar
    61 posts
    Member since:
    Oct 2008

    Posted 09 Mar 2009 Link to this post

    Lana,

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

    Marty
  7. Marty
    Marty avatar
    61 posts
    Member since:
    Oct 2008

    Posted 09 Mar 2009 Link to this post

    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

  8. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 10 Mar 2009 Link to this post

    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.
  9. Marty
    Marty avatar
    61 posts
    Member since:
    Oct 2008

    Posted 11 Mar 2009 Link to this post

    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
  10. Marty
    Marty avatar
    61 posts
    Member since:
    Oct 2008

    Posted 11 Mar 2009 Link to this post

    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
  11. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 13 Mar 2009 Link to this post

    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.
  12. Marty
    Marty avatar
    61 posts
    Member since:
    Oct 2008

    Posted 13 Mar 2009 Link to this post

    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.
  13. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 16 Mar 2009 Link to this post

    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.
  14. Gary
    Gary avatar
    21 posts
    Member since:
    Feb 2008

    Posted 10 May 2010 Link to this post

    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.


  15. Tommy
    Tommy avatar
    6 posts
    Member since:
    Apr 2012

    Posted 19 Nov 2014 in reply to Iana Tsolova Link to this post

    This demo doesn't work. It looks like the code to do the custom filtering was left out
  16. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 24 Nov 2014 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017