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

Radgrid With Filter Template

3 Answers 59 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kavita
Top achievements
Rank 1
Kavita asked on 08 Jul 2013, 02:03 PM
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.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 09 Jul 2013, 08:33 AM
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
0
Kavita
Top achievements
Rank 1
answered on 09 Jul 2013, 09:29 AM
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.
0
Princy
Top achievements
Rank 1
answered on 10 Jul 2013, 07:21 AM
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
Tags
General Discussions
Asked by
Kavita
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Kavita
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or