How to highlight text without filtering

5 posts, 0 answers
  1. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 29 Aug 2011 Link to this post

    Hello,
    I'm using a combobox to let the user search items.
    The thing is that I want the text the user entered be highlighted in the different items but without using the Filter property.
    The filtering for my query is done in the server. I want the text be highlighted if there are corresponding results but continue to display all the items returned from the server even if there is no match in the text.
    The thing is that my users are allowed to search items on criteria that may not be displayed in the comboboxes item list.
    What I mean for example, is that I can have the following items to lookup for:
    index, name
    0, john
    1, jeanne
    2, jo

    the combobox only shows the names of the people.

    when I search for 'jo' the CBB should display two items, jo and john and higlight the 'jo' part of both items.
    But now when I search for '2', it should display one item 'jo' without any highligh in that case...

    How can this be done ?

    Here is the code I use:
    <telerik:RadComboBox ID="cbbMagasin" runat="server" Width="450px" Height="150px"
                ClientIDMode="Static" Filter="Contains" EmptyMessage="Choisir un magasin..."
                EnableLoadOnDemand="True" ShowMoreResultsBox="true" ItemsPerRequest="20" EnableVirtualScrolling="true"
                OnClientDropDownOpening="cbbMagasin_DropDownOpening" OnItemsRequested="cbbMagasin_ItemsRequested"
                LoadingMessage="Chargement..." Localization-NoMatches="Aucune correspondance"
                MarkFirstMatch="True">
            </telerik:RadComboBox>

    protected void cbbMagasin_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
            {
                RadComboBox cbbMagasin = sender as RadComboBox;
     
                cbbMagasin.Items.Clear();
     
                var magasins = DbContext.Magasins.Where(p => p.Ville.Contains(e.Text) || p.Enseigne.Contains(e.Text) || p.CodePDV.Contains(e.Text)).OrderBy(p => p.Enseigne).ThenBy(p => p.Ville);
     
                foreach (Magasin m in magasins)
                {
                    RadComboBoxItem item = new RadComboBoxItem();
     
                    item.Text = NamingHelpers.MagasinLabel(m);
                    item.Value = m.MagasinID.ToString();
                    cbbMagasin.Items.Add(item);
     
                    item.DataBind();
                }
            }

    You can see that the user can search by CodePDV even if CodePDV is not displayed in the CBB.

    Thank you for you help,
    John.
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 05 Sep 2011 Link to this post

    Hi John,

    I tried to find a straightforward way to achieve the behaviour that you describe - but unfortunately without success.

    In general highlighting the part of the item texts that match the RadComboBox input text is typical only for the Filter feature. Additionally the Filter and Load On Demand are not intended to be used together simply because they make the same thing – the first feature filters items at client-side and the second does this at server-side.
    Let me suggest you take a look at this online demo - you can observe the behaviour of the main RadComboBox features there.

    Best wishes,
    Kalina
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 09 Sep 2011 Link to this post

    Hello Kalina,
    Thank you for having looked into this...
    Sadly your demo does not add anything to my problem. I know the control pretty well already.

    I don't see a valid reason for binding the filter feature with the highlight feature...

    You are right, the filter is a local feature whereas the load on demand is a server thing... So, why should they do the same...

    That is why I use the load on demand to return a list of items specially crafted and the local filter is only meant to help the user easier find what he needs.

    So right now, the only choice I get is making all the searchable properties of my items visible in the dropdown so that filter + highlight can deal with them.

    Thanks anyway.
    John.  
  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 15 Sep 2011 Link to this post

    Hi John,

    Let me explain you how the Filter and Load On Demand work.
    Load On Demand fires when the user types in the input area or clicks on the drop-down toggle image when there are no items in the combobox. This feature is created to be fast.
    So every time user types in control input,  the “filtered” items will be populated in control dropdown in case you handle the ItemsRequested event at server side and “filter” them.

    In case you use only Filter – all items will be loaded initially, and then will be filtered at client-side.

    If you use both features at the same time - when user types at control input – there will be a request for items(and “filtered” items will be returned). Then Filter will perform again filtering at client-side.

    Kind regards,
    Kalina
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
  6. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 15 Sep 2011 Link to this post

    Hello Калина,
    Thank you for the details. I think I got that now.
    The only issue I have left is that you cannot highlight text in the client side items without using client side filtering.
    I do not want to use client side filtering. I'm doing it on the server...
    I just want to highlight the corresponding text, that's all.
    But I can't, because the two features are linked together ;)
    It's not very important any more. I did use an other way.
    Anyway, thank you very much for your help,
    John.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017