Class \Prado\Web\UI\WebControls\TRepeater
TRepeater displays its content repeatedly based on the data fetched from \Prado\Web\UI\WebControls\setDataSource. The repeated contents in TRepeater are called items, which are controls and can be accessed through \Prado\Web\UI\WebControls\getItems. When 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 IDataRenderer, the Data property will be set as the data row during databinding. Many PRADO controls implement this interface, such as TLabel, TTextBox, etc.
- If the class implements 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). TRepeaterItemRenderer may be used as the convenient base class which already implements IDataItemRenderer.
The following properties are used to specify different types of template and renderer for a repeater:
- \Prado\Web\UI\WebControls\setItemTemplate, \Prado\Web\UI\WebControls\setItemRenderer: for each repeated row of data
- \Prado\Web\UI\WebControls\setAlternatingItemTemplate, \Prado\Web\UI\WebControls\setAlternatingItemRenderer: for each alternating row of data. If not set, \Prado\Web\UI\WebControls\setItemTemplate or \Prado\Web\UI\WebControls\setItemRenderer will be used instead.
- \Prado\Web\UI\WebControls\setHeaderTemplate, \Prado\Web\UI\WebControls\setHeaderRenderer: for the repeater header.
- \Prado\Web\UI\WebControls\setFooterTemplate, \Prado\Web\UI\WebControls\setFooterRenderer: for the repeater footer.
- \Prado\Web\UI\WebControls\setSeparatorTemplate, \Prado\Web\UI\WebControls\setSeparatorRenderer: for content to be displayed between items.
- \Prado\Web\UI\WebControls\setEmptyTemplate, \Prado\Web\UI\WebControls\setEmptyRenderer: 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 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 \Prado\Web\UI\WebControls\onItemCreated:
- add the item as a child control
- call dataBind() of the item
- raise \Prado\Web\UI\WebControls\onItemDataBound:
TRepeater raises an \Prado\Web\UI\WebControls\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 \Prado\Web\UI\WebControls\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 \Prado\Web\UI\WebControls\getDataKeys 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.
Class hierarchy
- \Prado\Web\UI\WebControls\TRepeater implements INamingContainer
- \Prado\Web\UI\WebControls\TDataBoundControl
- \Prado\Web\UI\WebControls\TWebControl implements IStyleable
- \Prado\Web\UI\TControl implements IRenderable, IBindable
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.0
public
|
bubbleEvent(TControl $sender, TEventParameter $param) : bool
This method overrides parent's implementation to handle
{@see onItemCommand OnItemCommand} event which is bubbled from
repeater items and their child controls.
This method should only be used by control developers. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
loadState() : mixed
Loads item count information from viewstate.
This method is invoked right after control state is loaded. |
public
|
onItemCommand(TRepeaterCommandEventParameter $param) : mixed
Raises <b>OnItemCommand</b> event.
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
|
onItemCreated(TRepeaterItemEventParameter $param) : mixed
Raises <b>OnItemCreated</b> event.
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
|
onItemDataBound(TRepeaterItemEventParameter $param) : mixed
Raises <b>OnItemDataBound</b> event.
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
|
render(THtmlWriter $writer) : mixed
Renders the repeater.
This method overrides the parent implementation by rendering the body content as the whole presentation of the repeater. Outer tag is not rendered. |
public
|
|
public
|
saveState() : mixed
Saves item count in viewstate.
This method is invoked right before control state is to be saved. |
public
|
setAlternatingItemRenderer(string $value) : mixed
Sets the alternative item renderer class.
If not empty, the class will be used to instantiate as alternative repeater items. This property takes precedence over \Prado\Web\UI\WebControls\getAlternatingItemTemplate. |
public
|
|
public
|
|
public
|
setEmptyRenderer(string $value) : mixed
Sets the repeater empty renderer class.
The empty renderer is created as the child of the repeater if data bound to the repeater is empty. This property takes precedence over \Prado\Web\UI\WebControls\getEmptyTemplate. |
public
|
|
public
|
setFooterRenderer(string $value) : mixed
Sets the repeater footer renderer class.
If not empty, the class will be used to instantiate as repeater footer item. This property takes precedence over \Prado\Web\UI\WebControls\getFooterTemplate. |
public
|
|
public
|
setHeaderRenderer(string $value) : mixed
Sets the repeater header renderer class.
If not empty, the class will be used to instantiate as repeater header item. This property takes precedence over \Prado\Web\UI\WebControls\getHeaderTemplate. |
public
|
|
public
|
setItemRenderer(string $value) : mixed
Sets the item renderer class.
If not empty, the class will be used to instantiate as repeater items. This property takes precedence over \Prado\Web\UI\WebControls\getItemTemplate. |
public
|
|
public
|
setSeparatorRenderer(string $value) : mixed
Sets the repeater item separator renderer class.
If not empty, the class will be used to instantiate as repeater item separators. This property takes precedence over \Prado\Web\UI\WebControls\getSeparatorTemplate. |
public
|
|
protected
|
|
protected
|
createItem(int $itemIndex, TListItemType $itemType) : TControl
Creates a repeater item instance based on the item type and index.
|
protected
|
getDataFieldValue(mixed $data, string $field) : mixed
Returns the value of the data at the specified field.
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
|
performDataBinding(Traversable $data) : mixed
Performs databinding to populate repeater items from data source.
This method is invoked by dataBind(). You may override this function to provide your own way of data population. |
protected
|
|
private
|
createItemInternal(int $itemIndex, TListItemType $itemType) : TControl
Creates a repeater item.
This method invokes createItem to create a new repeater item. |
private
|
createItemWithDataInternal(int $itemIndex, TListItemType $itemType, mixed $dataItem) : TControl
Creates a repeater item and performs databinding.
This method invokes createItem to create a new repeater item. |