Ajaxfied RadGrid RadCombo FilterTemplate

5 posts, 1 answers
  1. prakash
    prakash avatar
    3 posts
    Member since:
    Jun 2015

    Posted 27 Jun 2015 Link to this post


    I want to know how to implement custom filter in RadGrid.

    I have a Ajaxfied RadGrid and datasource is binded in NeedDatasource event. The RadGrid has five columns..

    In that, I want to change the filter of one of the column to selectable filter..

    So, I added a FilterTemplate and added the RadComboBox inside to it..

    Initially, I hardcoded all the RadComboBox item in the design time itself.. Binded a javascript to clientside_selectedchanged event.. This approach worked fine..

    When I binded RadComboBox with collection (List) in the code behind.. The filtering didn't work.. I binded the RadComboBox in GridItemDataBound or GridItemCreated event.. But no luck..

    Any help.. will be very much useful to me.. I spent nearly two days but I didn't any direction... I'm nearing to my deadline.. so I have no other option left out other than this forum..

    Custom Filter Code

    The following is sample code which I copied from my project and pasted here.. I have changed the field names alone..

    Filter Template:

    <telerik:GridBoundColumn DataField="DepartmentDescription" Groupable="true" HeaderText="Program" UniqueName="DepartmentDescription">

        <FilterTemplate>

            <telerik:RadComboBox ID="RadComboBoxDepartmentDescription" runat="server"

                AppendDataBoundItems="true"

                DataTextField="DepartDesc"

                DataValueField=" DepartDesc "

                OnClientSelectedIndexChanged="RadComboBoxDepartmentDescriptionIndexChanged"

                OnDataBound="RadComboBoxAllFilters_OnDataBound"

                SelectedValue='<%#TryCast(Container,GridItem).OwnerTableView.GetColumn("DepartmentDescription ").CurrentFilterValue%>'

                Width="100px">

                <Items>

                    <telerik:RadComboBoxItem Text="All" Value="" />

                </Items>

            </telerik:RadComboBox>

            <telerik:RadScriptBlock ID="RadScriptBlockProgram" runat="server">

                <script type="text/javascript">



                    function RadComboBoxDepartmentDescriptionIndexChanged(sender, args) {

                        var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID%>");

                        tableView.filter("DepartmentDescription", args.get_item().get_value(), "EqualTo");

                    }

                </script> 

            </telerik:RadScriptBlock>

        </FilterTemplate>

        <ItemStyle Wrap="False" />

        <HeaderStyle Wrap="false" />

    </telerik:GridBoundColumn>





    RadGrid DataBinding Code

    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {

    (sender as RadGrid).DataSource = employeeList;  //This is a list of employee of values.. which comes from service layer.. of type .. List<Employee>

    }



    RadGrid UI Code


    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

            <AjaxSettings>

                <telerik:AjaxSetting AjaxControlID="RadGrid1">

                    <UpdatedControls>

                        <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>

                    </UpdatedControls>

                </telerik:AjaxSetting>

            </AjaxSettings>

        </telerik:RadAjaxManager>

        <div>

            <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="true"

                OnNeedDataSource="RadGrid1_NeedDataSource"

    ..other code I removed it.. like the grid events and bound columns definitions

            </telerik:RadGrid>



    RadComboBox Filter DataBinding Code in the Code Behind:

    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound

    If TypeOf e.Item Is Telerik.Web.UI.GridFilteringItem Then

        'Populate Filters by binding the combo to datasource

        Dim filteringItem As Telerik.Web.UI.GridFilteringItem = CType(e.Item, Telerik.Web.UI.GridFilteringItem)

        Dim myRadComboBox As Telerik.Web.UI.RadComboBox = DirectCast(filteringItem.FindControl("RadComboBoxDepartmentDescription"),Telerik.Web.UI.RadComboBox)



        myRadComboBox.DataSource = departmentList; //This is a collection which comes from service layer… and the type is List<Department>

        myRadComboBox.DataTextField = " DepartmentDescription"
        myRadComboBox.DataValueField = " DepartmentDescription"

        myRadComboBox.DataBind()

    End If



    Even I pasted the same code in ItemCreated Event as well but no luck…

     

  2. Eyup
    Admin
    Eyup avatar
    3802 posts

    Posted 02 Jul 2015 Link to this post

    Hello Prakash,

    You can find here an actual running live sample:
    http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx

    In addition, I am sending a RadGrid web site to demonstrate more advanced scenarios.

    Hope this helps.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. prakash
    prakash avatar
    3 posts
    Member since:
    Jun 2015

    Posted 02 Jul 2015 in reply to Eyup Link to this post

    Thanks Eyup...

    can you give me simple example project and it should do the following

    1. RadGrid should be binded in needdatasource event (Advanced bindind)
    2. RadComboBox filter should be added to one of the column.. the datasource for the radcombobox should be binded in the codebehind. not in the design time..

     

  4. prakash
    prakash avatar
    3 posts
    Member since:
    Jun 2015

    Posted 02 Jul 2015 in reply to Eyup Link to this post

    Thanks Eyup...can you give me simple sample example project and it should do the following

    1. RadGrid should be binded in needdatasource event (Advanced bindind)
    2. RadComboBox filter should be added to one of the column.. the datasource for the radcombobox should be binded in the codebehind. not in the design time..

    3. Generic collection (something like List<employee>) should be used.. not sqldatasource..

    I binded the radcombo in design time and it works.. only when I bind it in code behind it fails..

     

    If you can give me solution then it will be great help for me..

     

     Thanks,

    Prakash..

  5. Answer
    Eyup
    Admin
    Eyup avatar
    3802 posts

    Posted 07 Jul 2015 Link to this post

    Hi,

    I am sending another sample to demonstrate the requested functionality. Please run the attached application and let me know if it helps you.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top