C1Combobox - How to select All item (client side)

Posted by: cglaude on 10 September 2017, 11:34 am EST

  • Posted 10 September 2017, 11:34 am EST

    Hi,

    This is actually verry simple, but I'm new to Javascript...

    I need from the client side to select all the items from the combobox. I successfully did an exemple by using the collection from the "selecteditems" method and it work well. But What I need is to select all item in the combobox.


    Here's my code...


    function CheckComboLocalisationStatus() {</pre>
      var combo = Sys.Application.findComponent("<%=C1CboLocalisation.ClientID%>");
      var selectedItem = combo.get_selectedItem();
      var text = selectedItem.get_text();</pre>
      if (text == 'All') {
        var _count = combo.get_items().get_count();
        for (i = 0; i < _count -1; i++) {
          var item = combo.get_items(i);
          combo.get_items(i).set_selected(true); <---- Error occured here
        }
      } </pre>
    } </pre>



    </pre>

    </pre>

    </pre>

    </pre>


    </pre>
    </pre>

     


     

  • Replied 10 September 2017, 11:34 am EST

    Hello,


    The following code should help you achieve your requirement:



    function SelectAll() {
    var combo = $find("C1ComboBox1");

    // sets SelectionMode to Multiple
    if (combo.get_selectionMode() == 0)
    combo.set_selectionMode(1);

    var items = combo.get_items();
    var count = items.get_count();

    var text = "";
    for (i = 0; i < count; i++) {
    var item = items.get_item(i);
    item.set_selected(true);
    text += item.get_text() + "; ";
    }

    combo.set_text(text);
    }

    function ClearSelection() {
    var combo = $find("C1ComboBox1");

    var items = combo.get_items();
    var count = items.get_count();

    for (i = 0; i < count; i++) {
    var item = items.get_item(i);
    item.set_selected(false);
    }

    combo.set_text("");
    }</pre>
    This code to deselect the items is also included.  If you have any problems with this, please let me know and I will see what I can do.


     


    Thanks,


    -Raleigh

  • Replied 10 September 2017, 11:34 am EST

    Thanks, that works great !

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels