This is a migrated thread and some comments may be shown as answers.
How to reset RadComboBox with Checkboxes using Javascript
12 Answers 275 Views
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 24 Jan 2012, 08:28 PM
I am hoping this is a fairly easy one - but have not found any documentation on it.

I have several ComboBoxes on a page that use the new(ish) checkbox feature for each item.  When the user clicks a Clear button, I would like to uncheck any checked items in each Combobox, and if necessary, reset to the EmptyMessage.  This does not seem to work:

function clearFilters(sender, args) {
                var combo = $find("<%= RadComboBox1.ClientID %>");
                combo.clearItems;
                combo.clearSelection;
}

12 Answers, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 1
answered on 25 Jan 2012, 12:03 AM
Think I figured it out - using code from this link:

http://www.telerik.com/community/forums/aspnet-ajax/combobox/clearcheckeditems-on-client-side.aspx 

    combo.trackChanges();
    for (var i = 0; i < combo.get_items().get_count(); i++) {
        combo.get_items().getItem(i).set_checked(false);
    }
    combo.commitChanges();


Is there any way I can loop through only a collection of the selected items on a given Combobox?  One of mine has over 1,000 items in it and is noticable slow looping through to try and determine if there are any to uncheck. ???
0
Dan
Top achievements
Rank 1
answered on 26 Jan 2012, 02:45 AM
Performance is really a dog for me on this.  Is there any way to only get the selecteditems back from a RadComboBox, so I  can just unselect those?
0
Kalina
Telerik team
answered on 27 Jan 2012, 04:25 PM
Hi Dan,

Please try using the get_checkedItems() method.


All the best,
Kalina
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
0
Dan
Top achievements
Rank 1
answered on 27 Jan 2012, 04:57 PM
Thank you for the reply Kalina - I tried this, but it says that there is no get_count() method:

function clearCheckboxes(combo, args) {
    for (var i = 0; i < combo.get_checkedItems().get_count(); i++) {
        combo.get_checkedItems().getItem(i).set_checked(false);
    }
}

EDIT: I should clarify that I am calling this routine from a button click, and it loops through several comboboxes to clear out any selected values.  It seems that get_checkedItems only works when you are coming in directly from a checked event???
0
Accepted
Kalina
Telerik team
answered on 27 Jan 2012, 05:37 PM
Hello Dan,

As is described in the help article that I’ve already mentioned: “get_checkedItems: gets an array of the checked RadComboBoxItem objects”.
Please use the length property of the array.
Additionally I am not sure that your approach for unchecking items is precise enough, please try the code above:
<script type="text/javascript">
    function Uncheck() {
        var combo = $find("<%=RadComboBox1.ClientID %>");
        var items = combo.get_checkedItems();
 
        var i = 0;
        while (i < items.length) {
            items[i].uncheck();
            i++;
        }
    }
</script>
<telerik:RadComboBox ID="RadComboBox1" runat="server" EmptyMessage="check items"
    CheckBoxes="true" EnableCheckAllItemsCheckBox="true">
    <Items>
        <telerik:RadComboBoxItem Text="item 1" Value="1" />
        <telerik:RadComboBoxItem Text="item 2" Value="2" />
        <telerik:RadComboBoxItem Text="item 3" Value="3" />
        <telerik:RadComboBoxItem Text="item 4" Value="4" />
    </Items>
</telerik:RadComboBox>
<asp:Button ID="Button1" runat="server" OnClientClick="Uncheck()" Text="Uncheck" />


Regards,
Kalina
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
0
Dan
Top achievements
Rank 1
answered on 27 Jan 2012, 05:53 PM
Excellent - thank you for straightening me out on that one.  It works!  
0
Joel R
Top achievements
Rank 1
answered on 02 Jan 2014, 09:38 PM
The solution works great but how do you get the empty message to show after the selections are cleared?
0
Princy
Top achievements
Rank 1
answered on 03 Jan 2014, 03:27 AM
Hi Joel R,

This is the default behavior of RadComboBox EmptyMessage property. The EmptyMessage property of the RadComboBox enables the ability to set any text in the input field of the control. This text is not visible when the combobox gets the focus and appears again on blur if no item is selected. So when the selections are cleared EmptyMessage will automatically come.

Thanks,
Princy.

0
Krishna
Top achievements
Rank 1
answered on 22 Jun 2015, 01:07 PM

Hi,

I am getting following error.When I use the above code. 

Object doesn't support property or method 'get_checkedItems'

Please suggest.

Thanks,

Krishna

0
Nencho
Telerik team
answered on 25 Jun 2015, 07:38 AM
Hello Krishna,

The get_checkedItems method is available and it does return the collection of the checked items for a given RadComboBox. Please make sure that you have correctly acquired a reference for the RadComboBox object that you invoke the method on.

Regards,
Nencho
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Krishna
Top achievements
Rank 1
answered on 25 Jun 2015, 01:46 PM

Hi Nencho,

Many thanks,.

Finally I got some reply form this telerik forum. Nice to see. 

This method works fine If i test in server not working when I test locally using VS2012.

Again thanks for the reply.

 

Regards,

Krishna

 

 

0
Gowtham
Top achievements
Rank 1
answered on 03 Jul 2015, 06:31 AM

Hi Kalina 

              Excellent  - Working fine, Thank you

Asked by
Dan
Top achievements
Rank 1
Answers by
Dan
Top achievements
Rank 1
Kalina
Telerik team
Joel R
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Krishna
Top achievements
Rank 1
Nencho
Telerik team
Gowtham
Top achievements
Rank 1
Share this question
or