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

show the combobox typed text part of items in bold

1 Answer 168 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sampada
Top achievements
Rank 1
Sampada asked on 15 Mar 2012, 10:56 AM

Team

I am using radcombobox in my application.

I am using it to implement search functionality. whenever we type something in combobox the resulting items is getting displayed in the combo list properly

& when result is not there it should display “no result found” & should give a link to a page which is used to add the items in that combobox.This I have added in the list of items .It is working.(attached is the screenshot for this requirement img.)

For this I am using OnItemsRequested event.

I have a requirement to show text of items in bold which I am typing in combobox. (attached is the screenshot for this requirement1 img.)
This feature is working when I set Filter ="Contains" but for displaying “no result found” & should give a link to a page which is used to add the items in that combobox requirement I can’t set this property. If I set this property it won’t show “no result found” & link .

I have tried to set it by <b> tab but it shows <b> tag as it is in item text.

Is there another way to show the combobox typed text part of items in bold?

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 16 Mar 2012, 03:17 PM
Hello Sampada,

Here is what you can do to replace the Filter functionality:
function OnClientItemsRequesting(sender, args) {
    if (sender.get_text() == "")
        args.set_cancel(true);
}
 
function OnClientItemsRequested(sender, args) {
    if (sender.get_text() != "") {
        var escapedText = regEx(sender.get_text());
        regex = new RegExp("^\\s*" + escapedText, "im");
        sender.get_items().forEach(function (item, index) {
            item._highlight(regex, item.get_element());
        });
    }
}
 
function regEx(text) {
    return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
<telerik:RadComboBox ID="RadComboBox1" runat="server" Width="250px" Height="150px"
    EmptyMessage="Select a Company" EnableLoadOnDemand="True" OnItemsRequested="RadComboBox1_ItemsRequested"
    OnClientItemsRequested="OnClientItemsRequested"
OnClientItemsRequesting="OnClientItemsRequesting">
</telerik:RadComboBox>

I hope this helps.

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Sampada
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or