PHP Class Prado\Web\UI\WebControls\TRepeater

TRepeater displays its content repeatedly based on the data fetched from {@link setDataSource DataSource}. The repeated contents in TRepeater are called items, which are controls and can be accessed through {@link getItems Items}. When {@link dataBind()} is invoked, TRepeater creates an item for each row of data and binds the data row to the item. Optionally, a repeater can have a header, a footer and/or separators between items. The layout of the repeated contents are specified by inline templates. Repeater items, header, footer, etc. are being instantiated with the corresponding templates when data is being bound to the repeater. Since v3.1.0, the layout can also be specified by renderers. A renderer is a control class that can be instantiated as repeater items, header, etc. A renderer can thus be viewed as an external template (in fact, it can also be non-templated controls). A renderer can be any control class. - If the class implements {@link \Prado\IDataRenderer}, the Data property will be set as the data row during databinding. Many PRADO controls implement this interface, such as {@link TLabel}, {@link TTextBox}, etc. - If the class implements {@link IItemDataRenderer}, the ItemIndex property will be set as the zero-based index of the item in the repeater item collection, and the ItemType property as the item's type (such as TListItemType::Item). {@link TRepeaterItemRenderer} may be used as the convenient base class which already implements {@link IDataItemRenderer}. The following properties are used to specify different types of template and renderer for a repeater: - {@link setItemTemplate ItemTemplate}, {@link setItemRenderer ItemRenderer}: for each repeated row of data - {@link setAlternatingItemTemplate AlternatingItemTemplate}, {@link setAlternatingItemRenderer AlternatingItemRenderer}: for each alternating row of data. If not set, {@link setItemTemplate ItemTemplate} or {@link setItemRenderer ItemRenderer} will be used instead. - {@link setHeaderTemplate HeaderTemplate}, {@link setHeaderRenderer HeaderRenderer}: for the repeater header. - {@link setFooterTemplate FooterTemplate}, {@link setFooterRenderer FooterRenderer}: for the repeater footer. - {@link setSeparatorTemplate SeparatorTemplate}, {@link setSeparatorRenderer SeparatorRenderer}: for content to be displayed between items. - {@link setEmptyTemplate EmptyTemplate}, {@link setEmptyRenderer EmptyRenderer}: used when data bound to the repeater is empty. If a content type is defined with both a template and a renderer, the latter takes precedence. When {@link dataBind()} is being called, TRepeater undergoes the following lifecycles for each row of data: - create item based on templates or renderers - set the row of data to the item - raise {@link onItemCreated OnItemCreated}: - add the item as a child control - call dataBind() of the item - raise {@link onItemDataBound OnItemDataBound}: TRepeater raises an {@link onItemCommand OnItemCommand} whenever a button control within some repeater item raises a OnCommand event. Therefore, you can handle all sorts of OnCommand event in a central place by writing an event handler for {@link onItemCommand OnItemCommand}. When a page containing a repeater is post back, the repeater will restore automatically all its contents, including items, header, footer and separators. However, the data row associated with each item will not be recovered and become null. To access the data, use one of the following ways: - Use {@link getDataKeys DataKeys} to obtain the data key associated with the specified repeater item and use the key to fetch the corresponding data from some persistent storage such as DB. - Save the whole dataset in viewstate, which will restore the dataset automatically upon postback. Be aware though, if the size of your dataset is big, your page size will become big. Some complex data may also have serializing problem if saved in viewstate.
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends TDataBoundControl, implements Prado\Web\UI\INamingContainer
Mostra file Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
bubbleEvent ( $sender, $param ) : boolean This method overrides parent's implementation to handle {@link onItemCommand OnItemCommand} event which is bubbled from repeater items and their child controls.
getAlternatingItemRenderer ( ) : string
getAlternatingItemTemplate ( ) : ITemplate
getDataKeyField ( ) : string
getDataKeys ( ) : Prado\Collections\TList
getEmptyRenderer ( ) : string
getEmptyTemplate ( ) : ITemplate
getFooter ( ) : TControl
getFooterRenderer ( ) : string
getFooterTemplate ( ) : ITemplate
getHeader ( ) : TControl
getHeaderRenderer ( ) : string
getHeaderTemplate ( ) : ITemplate
getItemRenderer ( ) : string
getItemTemplate ( ) : ITemplate
getItems ( ) : TRepeaterItemCollection
getSeparatorRenderer ( ) : string
getSeparatorTemplate ( ) : ITemplate
loadState ( ) Loads item count information from viewstate.
onItemCommand ( $param ) Raises OnItemCommand event.
onItemCreated ( $param ) Raises OnItemCreated event.
onItemDataBound ( $param ) Raises OnItemDataBound event.
render ( $writer ) Renders the repeater.
reset ( ) Clears up all items in the repeater.
saveState ( ) Saves item count in viewstate.
setAlternatingItemRenderer ( $value ) Sets the alternative item renderer class.
setAlternatingItemTemplate ( $value )
setDataKeyField ( $value )
setEmptyRenderer ( $value ) Sets the repeater empty renderer class.
setEmptyTemplate ( $value )
setFooterRenderer ( $value ) Sets the repeater footer renderer class.
setFooterTemplate ( $value )
setHeaderRenderer ( $value ) Sets the repeater header renderer class.
setHeaderTemplate ( $value )
setItemRenderer ( $value ) Sets the item renderer class.
setItemTemplate ( $value )
setSeparatorRenderer ( $value ) Sets the repeater item separator renderer class.
setSeparatorTemplate ( $value )

Protected Methods

Method Description
createEmptyContent ( ) Creates empty repeater content.
createItem ( $itemIndex, $itemType ) : TControl Creates a repeater item instance based on the item type and index.
getDataFieldValue ( $data, $field ) : mixed Returns the value of the data at the specified field.
performDataBinding ( $data ) Performs databinding to populate repeater items from data source.
restoreItemsFromViewState ( ) Creates repeater items based on viewstate information.

Private Methods

Method Description
createItemInternal ( $itemIndex, $itemType ) : TControl Creates a repeater item.
createItemWithDataInternal ( $itemIndex, $itemType, $dataItem ) : TControl Creates a repeater item and performs databinding.

Method Details

bubbleEvent() public method

This method should only be used by control developers.
public bubbleEvent ( $sender, $param ) : boolean
return boolean whether the event bubbling should stop here.

createEmptyContent() protected method

Creates empty repeater content.
protected createEmptyContent ( )

createItem() protected method

Creates a repeater item instance based on the item type and index.
protected createItem ( $itemIndex, $itemType ) : TControl
return TControl created repeater item

getAlternatingItemRenderer() public method

Since: 3.1.0
public getAlternatingItemRenderer ( ) : string
return string the class name for alternative repeater items. Defaults to empty, meaning not set.

getAlternatingItemTemplate() public method

public getAlternatingItemTemplate ( ) : ITemplate
return ITemplate the alternative template string for the item

getDataFieldValue() protected method

If data is an array, TMap or TList, the value will be returned at the index of the specified field. If the data is a component with a property named as the field name, the property value will be returned. Otherwise, an exception will be raised.
protected getDataFieldValue ( $data, $field ) : mixed
return mixed data value at the specified field

getDataKeyField() public method

public getDataKeyField ( ) : string
return string the field of the data source that provides the keys of the list items.

getDataKeys() public method

public getDataKeys ( ) : Prado\Collections\TList
return Prado\Collections\TList the keys used in the data listing control.

getEmptyRenderer() public method

Since: 3.1.0
public getEmptyRenderer ( ) : string
return string the class name for empty repeater item. Defaults to empty, meaning not set.

getEmptyTemplate() public method

public getEmptyTemplate ( ) : ITemplate
return ITemplate the template applied when no data is bound to the repeater

getFooter() public method

public getFooter ( ) : TControl
return TControl the footer item

getFooterRenderer() public method

Since: 3.1.0
public getFooterRenderer ( ) : string
return string the class name for repeater footer item. Defaults to empty, meaning not set.

getFooterTemplate() public method

public getFooterTemplate ( ) : ITemplate
return ITemplate the footer template

getHeader() public method

public getHeader ( ) : TControl
return TControl the header item

getHeaderRenderer() public method

Since: 3.1.0
public getHeaderRenderer ( ) : string
return string the class name for repeater header item. Defaults to empty, meaning not set.

getHeaderTemplate() public method

public getHeaderTemplate ( ) : ITemplate
return ITemplate the header template

getItemRenderer() public method

Since: 3.1.0
public getItemRenderer ( ) : string
return string the class name for repeater items. Defaults to empty, meaning not set.

getItemTemplate() public method

public getItemTemplate ( ) : ITemplate
return ITemplate the template for repeater items

getItems() public method

public getItems ( ) : TRepeaterItemCollection
return TRepeaterItemCollection list of repeater item controls

getSeparatorRenderer() public method

Since: 3.1.0
public getSeparatorRenderer ( ) : string
return string the class name for repeater item separators. Defaults to empty, meaning not set.

getSeparatorTemplate() public method

public getSeparatorTemplate ( ) : ITemplate
return ITemplate the separator template

loadState() public method

This method is invoked right after control state is loaded.
public loadState ( )

onItemCommand() public method

This method is invoked after a button control in a template raises OnCommand event. The repeater control responsible for the event can be determined from the event parameter. The event parameter also contains the information about the initial sender of the OnCommand event, command name and command parameter. You may override this method to provide customized event handling. Be sure to call parent's implementation so that event handlers have chance to respond to the event.
public onItemCommand ( $param )

onItemCreated() public method

This method is invoked after a repeater item is created and instantiated with template, but before added to the page hierarchy. The repeater item control responsible for the event can be determined from the event parameter. If you override this method, be sure to call parent's implementation so that event handlers have chance to respond to the event.
public onItemCreated ( $param )

onItemDataBound() public method

This method is invoked right after an item is data bound. The repeater item control responsible for the event can be determined from the event parameter. If you override this method, be sure to call parent's implementation so that event handlers have chance to respond to the event.
public onItemDataBound ( $param )

performDataBinding() protected method

This method is invoked by dataBind(). You may override this function to provide your own way of data population.
protected performDataBinding ( $data )

render() public method

This method overrides the parent implementation by rendering the body content as the whole presentation of the repeater. Outer tag is not rendered.
public render ( $writer )

reset() public method

Clears up all items in the repeater.
public reset ( )

restoreItemsFromViewState() protected method

Creates repeater items based on viewstate information.

saveState() public method

This method is invoked right before control state is to be saved.
public saveState ( )

setAlternatingItemRenderer() public method

If not empty, the class will be used to instantiate as alternative repeater items. This property takes precedence over {@link getAlternatingItemTemplate AlternatingItemTemplate}.
See also: setAlternatingItemTemplate
Since: 3.1.0
public setAlternatingItemRenderer ( $value )

setAlternatingItemTemplate() public method

public setAlternatingItemTemplate ( $value )

setDataKeyField() public method

public setDataKeyField ( $value )

setEmptyRenderer() public method

The empty renderer is created as the child of the repeater if data bound to the repeater is empty. This property takes precedence over {@link getEmptyTemplate EmptyTemplate}.
See also: setEmptyTemplate
Since: 3.1.0
public setEmptyRenderer ( $value )

setEmptyTemplate() public method

public setEmptyTemplate ( $value )

setFooterRenderer() public method

If not empty, the class will be used to instantiate as repeater footer item. This property takes precedence over {@link getFooterTemplate FooterTemplate}.
See also: setFooterTemplate
Since: 3.1.0
public setFooterRenderer ( $value )

setFooterTemplate() public method

public setFooterTemplate ( $value )

setHeaderRenderer() public method

If not empty, the class will be used to instantiate as repeater header item. This property takes precedence over {@link getHeaderTemplate HeaderTemplate}.
See also: setHeaderTemplate
Since: 3.1.0
public setHeaderRenderer ( $value )

setHeaderTemplate() public method

public setHeaderTemplate ( $value )

setItemRenderer() public method

If not empty, the class will be used to instantiate as repeater items. This property takes precedence over {@link getItemTemplate ItemTemplate}.
See also: setItemTemplate
Since: 3.1.0
public setItemRenderer ( $value )

setItemTemplate() public method

public setItemTemplate ( $value )

setSeparatorRenderer() public method

If not empty, the class will be used to instantiate as repeater item separators. This property takes precedence over {@link getSeparatorTemplate SeparatorTemplate}.
See also: setSeparatorTemplate
Since: 3.1.0
public setSeparatorRenderer ( $value )

setSeparatorTemplate() public method

public setSeparatorTemplate ( $value )