Base class for widgets that manage a list of selected data items.
See the dojox/widget/Selection reference documentation for more information.
Used across all instances a hash to cache attribute names and their getter and setter names.
In single selection mode, the selected item or in multiple selection mode the last selected item. Warning: Do not use this property directly, make sure to call set() or get() methods.
The list of selected items. Warning: Do not use this property directly, make sure to call set() or get() methods.
Valid values are:
Internal helper for directly changing an attribute value.
Directly change the value of an attribute on an object, bypassing any accessor setter. Also handles the calling of watch and emitting events. It is designed to be used by descendant class when there are two values of attributes that are linked, but calling .set() is not appropriate.
Parameter | Type | Description |
---|---|---|
name | String | The property to set. |
value | Mixed | The value to set in the property. |
Internal helper for directly changing an attribute value.
Private function that does a get based off a hash of names
Parameter | Type | Description |
---|---|---|
name | undefined | |
names | undefined | Hash of names of custom attributes |
Helper function for get() and set(). Caches attribute name values so we don't do the string ops every time.
Parameter | Type | Description |
---|---|---|
name | undefined |
Parameter | Type | Description |
---|---|---|
value | undefined |
Parameter | Type | Description |
---|---|---|
value | undefined |
Parameter | Type | Description |
---|---|---|
value | undefined |
Dispatch a selection change event.
Parameter | Type | Description |
---|---|---|
oldSelectedItem | Object | The previously selectedItem. |
newSelectedItem | Object | The new selectedItem. |
renderer | Object | The visual renderer of the selected/deselected item. |
triggerEvent | Event | The event that lead to the selection of the item. |
Get a property on a Stateful instance.
Get a named property on a Stateful object. The property may potentially be retrieved via a getter method in subclasses. In the base class this just retrieves the object's property.
Parameter | Type | Description |
---|---|---|
name | String | The property to get. |
The property value on this Stateful instance.
1 2 3 4 5 | require([ "dojo/Stateful" , function (Stateful) { var stateful = new Stateful({foo: 3}); stateful.get( "foo" ) // returns 3 stateful.foo // returns 3 }); |
This function must be implemented to return the id of a item.
Parameter | Type | Description |
---|---|---|
item | Object | The item to query the identity for. |
Returns whether an item is selected or not.
Parameter | Type | Description |
---|---|---|
item | Object | The item to test the selection for. |
Applies selection triggered by an user interaction
Parameter | Type | Description |
---|---|---|
e | Event | The source event of the user interaction. |
item | Object | The render item that has been selected/deselected. |
renderer | Object | The visual renderer of the selected/deselected item. |
dispatch | Boolean | Whether an event must be dispatched or not. |
Returns true if the selection has changed and false otherwise.
Set a property on a Stateful instance
Sets named properties on a stateful object and notifies any watchers of the property. A programmatic setter may be defined in subclasses.
Parameter | Type | Description |
---|---|---|
name | String | The property to set. |
value | Object | The value to set in the property. |
The function returns this dojo.Stateful instance.
1 2 3 4 5 6 | require([ "dojo/Stateful" , function (Stateful) { var stateful = new Stateful(); stateful.watch( function (name, oldValue, value){ // this will be called on the set below } stateful.set(foo, 5); |
set() may also be called with a hash of name/value pairs, ex:
1 2 3 4 5 | stateful.set({ foo: "Howdy" , bar: 3 }); }); |
This is equivalent to calling set(foo, "Howdy") and set(bar, 3)
Change the selection state of an item.
Parameter | Type | Description |
---|---|---|
item | Object | The item to change the selection state for. |
value | Boolean | True to select the item, false to deselect it. |
Watches a property for changes
Parameter | Type | Description |
---|---|---|
name | String |
Optional Indicates the property to watch. This is optional (the callback may be the only parameter), and if omitted, all the properties will be watched |
callback | Function | The function to execute when the property changes. This will be called after the property has been changed. The callback will be called with the |this| set to the instance, the first argument as the name of the property, the second argument as the old value and the third argument as the new value. |
An object handle for the watch. The unwatch method of this object can be used to discontinue watching this property:
1 2 | var watchHandle = obj.watch( "foo" , callback); watchHandle.unwatch(); // callback won't be called now |
Called when the selection changed.
1 2 3 4 5 6 | require([ "dojo/Stateful" , function (Stateful) { var stateful = new Stateful(); stateful.watch( function (name, oldValue, value){ // this will be called on the set below } stateful.set(foo, 5); |
set() may also be called with a hash of name/value pairs, ex:
1 2 3 4 5 | stateful.set({ foo: "Howdy" , bar: 3 }); }); |
This is equivalent to calling set(foo, "Howdy") and set(bar, 3)