Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
This class also supports single and multi selection modes.
Create a data model bound view:
var dataModel = new YAHOO.ext.grid.XMLDataModel(...);
var view = new YAHOO.ext.View('my-element',
'<div id="{0}">{2} - {1}</div>', // auto create template
dataModel, {
singleSelect: true,
selectedClass: 'ydataview-selected'
});
// listen for node click?
view.on('click', function(vw, index, node, e){
alert('Node "' + node.id + '" at index: ' + index + ' was clicked.');
});
// load XML data
dataModel.load('foobar.xml');
For an example of creating a JSON/UpdateManager view, see
YAHOO.ext.JsonView.
Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
IE's limited insertion support with tables and Opera's faulty event bubbling.
|
View(String/HTMLElement/Element container , String/DomHelper.Template tpl , DataModel dataModel , Object config ) |
View |
Create a new View |
|
addListener(String eventName , Function handler , [Object scope ], [boolean override ]) : void |
Observable |
Appends an event handler to this component |
|
bufferedListener(String eventName , Function handler , [Object scope ], [Number millis ]) : Function |
Observable |
Appends an event handler to this component that is buffered. If the event is triggered more than once
in the specifie... |
|
clearSelections([Boolean suppressEvent ]) : void |
View |
Clear all selections |
|
delayedListener(String eventName , Function handler , [Object scope ], [Number delay ]) : Function |
Observable |
Appends an event handler to this component that is delayed the specified number of milliseconds. This
is useful for e... |
|
findItemFromChild(HTMLElement node ) : HTMLElement |
View |
Returns the template node the passed child belongs to or null if it doesn't belong to one. |
|
fireEvent(String eventName , Object... args ) : Boolean |
Observable |
Fires the specified event with the passed parameters (minus the event name). |
|
getEl() : YAHOO.ext.Element |
View |
Returns the element this view is bound to. |
|
getNode(HTMLElement/String/Number nodeInfo ) : HTMLElement |
View |
Gets a template node. |
|
getNodes(Number startIndex , Number endIndex ) : Array |
View |
Gets a range template nodes. |
|
getSelectedIndexes() : Array |
View |
Get the indexes of the selected nodes. |
|
getSelectedNodes() : Array |
View |
Get the currently selected nodes. |
|
getSelectionCount() : Number |
View |
Get the number of selected nodes. |
|
indexOf(HTMLElement/String/Number nodeInfo ) : Number |
View |
Finds the index of the passed node |
|
on(String eventName , Function handler , [Object scope ], [boolean override ]) : void |
Observable |
Appends an event handler to this element (shorthand for addListener) |
|
prepareData(Array/Object data , Number index ) : void |
View |
Function to override to reformat the data that is sent to
the template for each node. |
|
purgeListeners() : void |
Observable |
Removes all listeners for this object |
|
refresh() : void |
View |
Refreshes the view. |
|
refreshNode(Number index ) : void |
View |
Refresh an individual node. |
|
removeListener(String eventName , Function handler , [Object scope ]) : void |
Observable |
Removes a listener |
|
select(Array/HTMLElement/String/Number nodeInfo , [Boolean keepExisting ], [Boolean suppressEvent ]) : void |
View |
Selects nodes. |
|
setDataModel(DataModel dataModel ) : void |
View |
Changes the data model this view uses and refresh the view. |
|
unplugDataModel(DataModel dataModel ) : void |
View |
Unplug the data model and stop updates. |
|
beforeselect : (YAHOO.ext.View this , HTMLElement node , Array selections ) |
View |
Fires before a selection is made. If any handlers return false, the selection is cancelled. |
|
click : (YAHOO.ext.View this , Number index , HTMLElement node , YAHOO.ext.EventObject e ) |
View |
Fires when a template node is clicked. |
|
contextmenu : (YAHOO.ext.View this , Number index , HTMLElement node , YAHOO.ext.EventObject e ) |
View |
Fires when a template node is right clicked. |
|
dblclick : (YAHOO.ext.View this , Number index , HTMLElement node , YAHOO.ext.EventObject e ) |
View |
Fires when a template node is double clicked. |
|
selectionchange : (YAHOO.ext.View this , Array selections ) |
View |
Fires when the selected nodes change. |
jsonData
public Object jsonData
The current json data or null
This property is defined by View.
jsonRoot
public String jsonRoot
The root property in the loaded json object that contains the data
This property is defined by View.
selectedClass
public YAHOO.ext.DomHelper.Template selectedClass
The css class to add to selected nodes
This property is defined by View.
tpl
public YAHOO.ext.DomHelper.Template tpl
The template used by this View
This property is defined by View.
addListener
public function addListener(String eventName
, Function handler
, [Object scope
], [boolean override
])
Appends an event handler to this component
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope (this object) for the handler
override
: boolean(optional) If true, scope becomes the scope
Returns:
bufferedListener
public function bufferedListener(String eventName
, Function handler
, [Object scope
], [Number millis
])
Appends an event handler to this component that is buffered. If the event is triggered more than once
in the specified time-frame, only the last one actually fires.
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope (this object) for the handler
millis
: Number(optional) The number of milliseconds to buffer (defaults to 250)
Returns:
clearSelections
public function clearSelections([Boolean suppressEvent
])
This method is defined by View.
delayedListener
public function delayedListener(String eventName
, Function handler
, [Object scope
], [Number delay
])
Appends an event handler to this component that is delayed the specified number of milliseconds. This
is useful for events that modify the DOM and need to wait for the browser to catch up.
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope (this object) for the handler
delay
: Number(optional) The number of milliseconds to delay (defaults to 1 millisecond)
Returns:
findItemFromChild
public function findItemFromChild(HTMLElement node
)
Returns the template node the passed child belongs to or null if it doesn't belong to one.
Parameters:
Returns:
HTMLElement
The template node
This method is defined by View.
fireEvent
public function fireEvent(String eventName
, Object... args
)
Fires the specified event with the passed parameters (minus the event name).
getEl
public function getEl()
Returns the element this view is bound to.
This method is defined by View.
getNode
public function getNode(HTMLElement/String/Number nodeInfo
)
This method is defined by View.
getNodes
public function getNodes(Number startIndex
, Number endIndex
)
Gets a range template nodes.
Parameters:
startIndex
: NumberendIndex
: Number
Returns:
This method is defined by View.
getSelectedIndexes
public function getSelectedIndexes()
Get the indexes of the selected nodes.
This method is defined by View.
getSelectedNodes
public function getSelectedNodes()
Get the currently selected nodes.
Parameters:
Returns:
Array
An array of HTMLElements
This method is defined by View.
getSelectionCount
public function getSelectionCount()
Get the number of selected nodes.
This method is defined by View.
indexOf
public function indexOf(HTMLElement/String/Number nodeInfo
)
Finds the index of the passed node
This method is defined by View.
on
public function on(String eventName
, Function handler
, [Object scope
], [boolean override
])
Appends an event handler to this element (shorthand for addListener)
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope (this object) for the handler
override
: boolean(optional) If true, scope becomes the scope
Returns:
prepareData
public function prepareData(Array/Object data
, Number index
)
Function to override to reformat the data that is sent to
the template for each node.
This method is defined by View.
purgeListeners
public function purgeListeners()
Removes all listeners for this object
refresh
public function refresh()
This method is defined by View.
refreshNode
public function refreshNode(Number index
)
Refresh an individual node.
This method is defined by View.
removeListener
public function removeListener(String eventName
, Function handler
, [Object scope
])
select
public function select(Array/HTMLElement/String/Number nodeInfo
, [Boolean keepExisting
], [Boolean suppressEvent
])
Selects nodes.
Parameters:
nodeInfo
: Array/HTMLElement/String/NumberAn HTMLElement template node, index of a template node, id of a template node or an array of any of those to select
keepExisting
: Boolean(optional) true to keep existing selections
suppressEvent
: Boolean(optional) true to skip firing of the selectionchange vent
Returns:
This method is defined by View.
setDataModel
public function setDataModel(DataModel dataModel
)
Changes the data model this view uses and refresh the view.
This method is defined by View.
unplugDataModel
public function unplugDataModel(DataModel dataModel
)
Unplug the data model and stop updates.
This method is defined by View.
beforeselect
public event beforeselect
Fires before a selection is made. If any handlers return false, the selection is cancelled.
Subscribers will be called with the following parameters:
This event is defined by View.
click
public event click
Fires when a template node is clicked.
Subscribers will be called with the following parameters:
This event is defined by View.
contextmenu
public event contextmenu
Fires when a template node is right clicked.
Subscribers will be called with the following parameters:
This event is defined by View.
dblclick
public event dblclick
Fires when a template node is double clicked.
Subscribers will be called with the following parameters:
This event is defined by View.
selectionchange
public event selectionchange
Fires when the selected nodes change.
Subscribers will be called with the following parameters:
This event is defined by View.