Radgrid With Filter Template

4 posts, 0 answers
  1. Kavita
    Kavita avatar
    39 posts
    Member since:
    Feb 2013

    Posted 08 Jul 2013 Link to this post

    hi,
    i have a radgrid,in which on of my bound column is like this

     <telerik:GridBoundColumn DataField="sInvoiceStatus"  
                        FilterControlAltText="Filter sInvoiceStatus column"  
                        HeaderText="Invoice Status" SortExpression="sInvoiceStatus" 
                        UniqueName="sInvoiceStatus"  >
                          <HeaderStyle Font-Size="Small"   Font-Bold ="true" Wrap ="false"  />
                         <ItemStyle  Width ="150px"  Wrap ="false" />
                                           <FilterTemplate>
                            <telerik:RadComboBox ID="cbInvoiceStatus" DataSourceID="ObjectDataSource2" DataTextField="sInvoiceStatus"  DropDownWidth ="200px"
                                DataValueField="sInvoiceStatus" Height="100px" AppendDataBoundItems="true" Skin="Windows7" SelectedValue='<%# CType(Container, GridItem).OwnerTableView.GetColumn("sInvoiceStatus").CurrentFilterValue %>'
                                runat="server" OnClientSelectedIndexChanged="InvoiceStatusIndexChanged"  OnClientBlur ="Combobox_OnClientBlur"
                    OnClientDropDownClosing ="OnClientDropDownClosing" AllowCustomText ="false"  Font-Names ="Arial font" Font-Size ="12px" Filter ="StartsWith" >
                                <Items>
                                    <telerik:RadComboBoxItem Text="All" />
                                    <telerik:RadComboBoxItem Text="Blank"  value="" />
                                   
                                </Items>
                            </telerik:RadComboBox>
                            <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
                                <script type="text/javascript">
                                       function InvoiceStatusIndexChanged(sender, args)
                                        {
                                            var tableView = $find("<%# CType(Container, GridItem).OwnerTableView.ClientID %>");
                                            tableView.filter("sInvoiceStatus", args.get_item().get_value(), "EqualTo");
                                        }
                                </script>
                            </telerik:RadScriptBlock>
                        </FilterTemplate>
                    </telerik:GridBoundColumn>

    Here i m binding radcombobox with my database for filter purpose.
    If i select "All" it filter correctly.
    but i also want to select "Blank" in which filter should give me all the values which are '' or NULL in my database.Right now it is giving me only "" value from database...but not NULL values.
    I couldnt find the solution.
    please help me with this.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Jul 2013 Link to this post

    Hi Kavitha,

    Please try the following code snippet for your requirement.The database null and " " are two different properties,which will give two different values.

    ASPX:
    <telerik:GridBoundColumn DataField="ShipCity" FilterControlAltText="Filter ShipCity column"
                HeaderText="ShipCity" SortExpression="ShipCity" UniqueName="ShipCity">
                <HeaderStyle Font-Size="Small" Font-Bold="true" Wrap="false" />
                <ItemStyle Width="150px" Wrap="false" />
                <FilterTemplate>
                    <telerik:RadComboBox ID="cbInvoiceStatus" DataSourceID="SqlDataSource1" DataTextField="ShipCity"
                        DropDownWidth="200px" DataValueField="ShipCity" Height="100px" AppendDataBoundItems="true"
                        Skin="Windows7" SelectedValue='<%# Container.OwnerTableView.GetColumn("ShipCity").CurrentFilterValue %>'
                        runat="server" OnClientSelectedIndexChanged="InvoiceStatusIndexChanged" AllowCustomText="false"
                        Font-Names="Arial font" Font-Size="12px" Filter="StartsWith">
                        <Items>
                            <telerik:RadComboBoxItem Text="All" />
                            <telerik:RadComboBoxItem Text="IsEmpty" Value=" " />
                            <telerik:RadComboBoxItem Text="IsNull" Value="Null" />
                        </Items>
                    </telerik:RadComboBox>
                    <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
                        <script type="text/javascript">
                            function InvoiceStatusIndexChanged(sender, args) {
                                var tableView = $find("<%# Container.OwnerTableView.ClientID %>");
                                var value = args.get_item().get_value();
                                if (value == "Null") {
                                    tableView.filter("ShipCity", args.get_item().get_value(), "IsNull");  // Check DB for null values
                                }
                                else {
                                    tableView.filter("ShipCity", args.get_item().get_value(), "EqualTo");
                                }
                            }
                        </script>
                    </telerik:RadScriptBlock>
                </FilterTemplate>
            </telerik:GridBoundColumn>

    Please let know if you have any concern.

    Thanks,
    Shinu
  3. Kavita
    Kavita avatar
    39 posts
    Member since:
    Feb 2013

    Posted 09 Jul 2013 Link to this post

    hey shinu..
    Thanks for your reply.
    But i needed a solution with which, i can select "blank" or any option from filter and it will give me result from database which are  " " as well as "NULL".
    i do not want two filters for that like IsNull and IsEmpty.
    Can you please help me.
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Jul 2013 Link to this post

    Hi Kavita,

    The database null and database empty returns two different results.The IsNull checks for only null values from the database,whereas IsEmpty(" ") checks dataField = '' ".
    Please have a look at this documentation on Filtering Functions.

    Thanks,
    Princy
Back to Top