How to reset RadComboBox with Checkboxes using Javascript

13 posts, 1 answers
  1. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 24 Jan 2012 Link to this post

    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;
    }

  2. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 24 Jan 2012 Link to this post

    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. ???
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 25 Jan 2012 Link to this post

    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?
  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 27 Jan 2012 Link to this post

    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
  6. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 27 Jan 2012 Link to this post

    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???
  7. Answer
    Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 27 Jan 2012 Link to this post

    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
  8. Dan
    Dan avatar
    124 posts
    Member since:
    Feb 2011

    Posted 27 Jan 2012 Link to this post

    Excellent - thank you for straightening me out on that one.  It works!  
  9. Joel R
    Joel R avatar
    25 posts
    Member since:
    Nov 2007

    Posted 02 Jan 2014 Link to this post

    The solution works great but how do you get the empty message to show after the selections are cleared?
  10. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Jan 2014 Link to this post

    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.

  11. Krishna
    Krishna avatar
    8 posts
    Member since:
    May 2012

    Posted 22 Jun 2015 in reply to Kalina Link to this post

    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

  12. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 25 Jun 2015 Link to this post

    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
  13. Krishna
    Krishna avatar
    8 posts
    Member since:
    May 2012

    Posted 25 Jun 2015 in reply to Nencho Link to this post

    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

     

     

  14. Gowtham
    Gowtham avatar
    7 posts
    Member since:
    Jun 2013

    Posted 03 Jul 2015 in reply to Kalina Link to this post

    Hi Kalina 

                  Excellent  - Working fine, Thank you

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017