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

Set selected value in RadComboBox after selecting with Google-like filtering

3 Answers 298 Views
Grid
This is a migrated thread and some comments may be shown as answers.
john81
Top achievements
Rank 1
john81 asked on 08 Apr 2014, 07:44 PM
I've implemented Google-like filtering in my RadGrid FilterTemplate column similar to how its described here.  It works great except when you make a selection the value doesn't stay present in the RadComboBox.  Is there a way to accomplish this?  I tried using sender.set_text() but it doesn't seem to work.


<telerik:GridBoundColumn DataField="last_name" DataType="System.String" HeaderText="Last Name" SortExpression="last_name"
    UniqueName="last_name" ShowFilterIcon="True" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains">
    <FilterTemplate>
        <telerik:RadComboBox runat="server" ID="rcblast" DataTextField="last_name" DataValueField="last_name" EnableEmbeddedSkins="False" Skin="2015"
            Width="100px" EnableLoadOnDemand="True" MarkFirstMatch="True" ShowToggleImage="False" OnClientDropDownOpening="lastName_ClientDropDownOpening"
            OnClientSelectedIndexChanged="lastName_ClientSelectedIndexChanged" OnClientItemsRequesting="lastName_ItemsRequested"
            OnItemsRequested="rcblast_ItemsRequested">
        </telerik:RadComboBox>
        <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
            <script type="text/javascript">
                function lastName_ClientSelectedIndexChanged(sender, args) {
                    $find("<%= rgTraining.ClientID %>").get_masterTableView().filter("last_name", args.get_item().get_text(), "StartsWith");
                     
                    // doesn't seem to work
                    sender.set_text(args.get_item().get_text());
                }
                function lastName_ItemsRequested(sender, args) {
                    if (args.get_text().length < 3)
                        args.set_cancel(true);
                    else
                        args.set_cancel(false);
                }
                function lastName_ClientDropDownOpening(sender, args) {
                    var comboText = sender.get_text();
                    if (comboText.length < 3) {                                   
                        args.set_cancel(true);
                    }
                }                                                                                    
            </script>
        </telerik:RadScriptBlock>
    </FilterTemplate>                       
 
    <ItemStyle VerticalAlign="Top" />
    <HeaderStyle HorizontalAlign="Left" VerticalAlign="Bottom" Font-Bold="True" Font-Underline="True" />                               
</telerik:GridBoundColumn>




3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Apr 2014, 08:40 AM
Hi,

Please add the following code to your RadComboBox to set the selected value on filter.

ASPX:
<telerik:RadComboBox runat="server" ID="rcblast"
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("last_name").CurrentFilterValue %>' . .  >

Thanks,
Princy
0
john81
Top achievements
Rank 1
answered on 09 Apr 2014, 02:44 PM
I would think that would work but it ends up causing an exception.

Selection out of range
Parameter name: value
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
 Exception Details: System.ArgumentOutOfRangeException: Selection out of range
Parameter name: value

I'm going to guess that is because the RadComboBox has no items at that point.  I was able to come up with a different approach by checking for GridFilteringItem in the ItemDataBound of the RadGrid.

if (e.Item is GridFilteringItem)
{
    var filterItem = (GridFilteringItem)e.Item;
    if (rgTraining.MasterTableView.GetColumn("last_name").CurrentFilterValue != "")
        filterItem["last_name"].Text = rgTraining.MasterTableView.GetColumn("last_name").CurrentFilterValue;
}


The weird thing about this approach is it turns the filter textbox into a label.  I'd like to to remain a textbox though.


0
Princy
Top achievements
Rank 2
answered on 10 Apr 2014, 05:54 AM
Hi,

Please try the following code snippet to set the selected text in RadComboBox:

C#:
if (e.Item is GridFilteringItem)
{
  var filterItem = (GridFilteringItem)e.Item;
  if (RadGrid1.MasterTableView.GetColumn("last_name").CurrentFilterValue != "")
  {
    RadComboBox last_name = (RadComboBox)filterItem.FindControl("rcblast");
    last_name.Text = RadGrid1.MasterTableView.GetColumn("last_name").CurrentFilterValue;
  }
}

Thanks,
Princy
Tags
Grid
Asked by
john81
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
john81
Top achievements
Rank 1
Share this question
or