Class \Prado\Web\UI\WebControls\TListControl
TListControl is a base class for list controls, such as TListBox, TDropDownList, TCheckBoxList, etc. It manages the items and their status in a list control. It also implements how the items can be populated from template and data source.
The property getItems returns a list of the items in the control. To specify or determine which item is selected, use the \Prado\Web\UI\WebControls\getSelectedIndex property that indicates the zero-based index of the selected item in the item list. You may also use \Prado\Web\UI\WebControls\getSelectedItem and \Prado\Web\UI\WebControls\getSelectedValue to get the selected item and its value. For multiple selection lists (such as TCheckBoxList and TListBox), property \Prado\Web\UI\WebControls\getSelectedIndices is useful.
TListControl implements \Prado\Web\UI\WebControls\setAutoPostBack which allows a list control to postback the page if the selections of the list items are changed. The \Prado\Web\UI\WebControls\setCausesValidation and \Prado\Web\UI\WebControls\setValidationGroup properties may be used to specify that validation be performed when auto postback occurs.
There are three ways to populate the items in a list control: from template, using \Prado\Web\UI\WebControls\setDataSource and using \Prado\Web\UI\WebControls\setDataSourceID. The latter two are covered in TDataBoundControl. To specify items via template, using the following template syntax:
<com:TListControl>
<com:TListItem Value="xxx" Text="yyy" >
<com:TListItem Value="xxx" Text="yyy" Selected="true" >
<com:TListItem Value="xxx" Text="yyy" >
</com:TListControl>
When \Prado\Web\UI\WebControls\setDataSource or \Prado\Web\UI\WebControls\setDataSourceID is used to populate list items, the \Prado\Web\UI\WebControls\setDataTextField and \Prado\Web\UI\WebControls\setDataValueField properties are used to specify which columns of the data will be used to populate the text and value of the items. For example, if a data source is as follows,
$dataSource=array(
array('name'=>'John', 'age'=>31),
array('name'=>'Cary', 'age'=>28),
array('name'=>'Rose', 'age'=>35),
);
setting \Prado\Web\UI\WebControls\setDataTextField and \Prado\Web\UI\WebControls\setDataValueField to 'name' and 'age' will make the first item's text be 'John', value be 31, the second item's text be 'Cary', value be 28, and so on. The \Prado\Web\UI\WebControls\setDataTextFormatString property may be further used to format how the item should be displayed. See formatDataValue() for an explanation of the format string.
The \Prado\Web\UI\WebControls\setPromptText and \Prado\Web\UI\WebControls\setPromptValue properties can be used to add a dummy list item that will be rendered first.
Class hierarchy
- \Prado\Web\UI\WebControls\TListControl implements IDataRenderer
- \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
|
addParsedObject(mixed $object) : mixed
Adds object parsed from template to the control.
This method adds only TListItem objects into the \Prado\Web\UI\WebControls\getItems collection. All other objects are ignored. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
getData() : string
Returns the value of the selected item with the lowest cardinal index.
This method is required by IDataRenderer. It is the same as getSelectedValue(). |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
loadState() : mixed
Loads items from viewstate.
This method is invoked right after control state is loaded. |
public
|
onSelectedIndexChanged(TEventParameter $param) : mixed
Raises OnSelectedIndexChanged event when selection is changed.
This method is invoked when the list control has its selection changed by end-users. |
public
|
onTextChanged(TEventParameter $param) : mixed
Raises OnTextChanged event when selection is changed.
This method is invoked when the list control has its selection changed by end-users. |
public
|
renderContents(THtmlWriter $writer) : mixed
Renders body content of the list control.
This method renders items contained in the list control as the body content. |
public
|
saveState() : mixed
Saves items into viewstate.
This method is invoked right before control state is to be saved. |
public
|
|
public
|
setAutoPostBack(bool $value) : mixed
Sets the value indicating if postback automatically.
An automatic postback to the server will occur whenever the user makes change to the list control and then tabs out of it. |
public
|
|
public
|
setData(string $value) : mixed
Selects an item by the specified value.
This method is required by IDataRenderer. It is the same as setSelectedValue(). |
public
|
|
public
|
|
public
|
setDataTextFormatString(string $value) : mixed
Sets data text format string.
The format string is used in TDataValueFormatter::format() to format the Text property value of each item in the list control. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
setSelectedValue(string $value) : mixed
Sets selection by item value.
Existing selections will be cleared if the item value is found in the item collection. Note, if the value is null, existing selections will also be cleared. |
public
|
|
public
|
|
public
|
|
protected
|
|
protected
|
createListItemCollection() : TListItemCollection
Creates a collection object to hold list items.
This method may be overriden to create a customized collection. |
protected
|
formatDataValue(string $formatString, mixed $value) : string
Formats the text value according to a format string.
If the format string is empty, the original value is converted into a string and returned. If the format string starts with '#', the string is treated as a PHP expression within which the token '{0}' is translated with the data value to be formated. Otherwise, the format string and the data value are passed as the first and second parameters in sprintf. |
protected
|
getClientClassName() : string
Gets the name of the javascript class responsible for performing postback for this control.
Derived classes may override this method and return customized js class names. |
protected
|
|
protected
|
|
protected
|
|
protected
|
performDataBinding(Traversable $data) : mixed
Performs databinding to populate list items from data source.
This method is invoked by dataBind(). You may override this function to provide your own way of data population. |
protected
|
|
protected
|
|
private
|