Home

# Class goog.ui.SelectionModel

Single-selection model. Dispatches a {@link goog.events.EventType.SELECT} event when a selection is made.

extends goog.events.EventTarget

Instance Method Summary
| `addItem(?Object item)` Adds an item at the end of the list.
| `addItemAt(?Object item, number index)` Adds an item at the given index.
| `addItems((Array.<(Object|null)>|null|undefined) items)` Bulk-adds items to the selection model. This is more efficient than calling {@link #addItem} for each new item.
| `clear()` Clears the selection model by removing all items from the selection.

`disposeInternal()`

Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:

    MyClass.prototype.disposeInternal = function() {
    MyClass.superClass_.disposeInternal.call(this);
    // Dispose logic for MyClass
    };

| `getFirst() ⇒ (Object|null|undefined)`
| `getItemAt(number index) ⇒ ?Object` Returns the item at the given 0-based index.
| `getItemCount() ⇒ number` Returns the number of items controlled by the selection model.
| `getItems() ⇒ !Array`
| `getLast() ⇒ (Object|null|undefined)`
| `getSelectedIndex() ⇒ number`
| `getSelectedItem() ⇒ ?Object`
| `getSelectionHandler() ⇒ ?Function` Returns the selection handler function used by the selection model to change the internal selection state of items under its control.
| `indexOfItem((Object|null|undefined) item) ⇒ number` Returns the 0-based index of the given item within the selection model, or -1 if no such item is found.
| `removeItem(?Object item)` Removes the given item (if it exists). Dispatches a {@code SELECT} event if the removed item was the currently selected item.
| `removeItemAt(number index)` Removes the item at the given index.

`selectItem_(?Object item, boolean select)`

Private helper; selects or deselects the given item based on the value of the {@code select} argument. If a selection handler has been registered (via {@link #setSelectionHandler}, calls it to update the internal selection state of the item. Otherwise, attempts to call {@code setSelected(Boolean)} on the item itself, provided the object supports that interface.

| `setSelectedIndex(number index)` Selects the item at the given index, deselecting any previously selected item, and dispatches a {@code SELECT} event.
| `setSelectedItem(?Object item)` Selects the given item, deselecting any previously selected item, and dispatches a {@code SELECT} event.

`setSelectionHandler(?Function handler)`

Sets the selection handler function to be used by the selection model to change the internal selection state of items under its control. The function must take two arguments: an item and a Boolean to indicate whether the item is to be selected or deselected. Selection handler functions are only needed if the items in the selection model don't natively support the {@code setSelected(Boolean)} interface.