PHP Class Prado\Web\UI\WebControls\TListControl

TListControl is a base class for list controls, such as {@link TListBox}, {@link TDropDownList}, {@link 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 {@link getItems} returns a list of the items in the control. To specify or determine which item is selected, use the {@link getSelectedIndex SelectedIndex} property that indicates the zero-based index of the selected item in the item list. You may also use {@link getSelectedItem SelectedItem} and {@link getSelectedValue SelectedValue} to get the selected item and its value. For multiple selection lists (such as {@link TCheckBoxList} and {@link TListBox}), property {@link getSelectedIndices SelectedIndices} is useful. TListControl implements {@link setAutoPostBack AutoPostBack} which allows a list control to postback the page if the selections of the list items are changed. The {@link setCausesValidation CausesValidation} and {@link setValidationGroup ValidationGroup} 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 {@link setDataSource DataSource} and using {@link setDataSourceID DataSourceID}. The latter two are covered in {@link TDataBoundControl}. To specify items via template, using the following template syntax: When {@link setDataSource DataSource} or {@link setDataSourceID DataSourceID} is used to populate list items, the {@link setDataTextField DataTextField} and {@link setDataValueField DataValueField} 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 {@link setDataTextField DataTextField} and {@link setDataValueField DataValueField} 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 {@link setDataTextFormatString DataTextFormatString} property may be further used to format how the item should be displayed. See {@link formatDataValue()} for an explanation of the format string. The {@link setPromptText PromptText} and {@link setPromptValue PromptValue} properties can be used to add a dummy list item that will be rendered first.
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends TDataBoundControl, implements Prado\IDataRenderer
Show file Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
addParsedObject ( $object ) Adds object parsed from template to the control.
clearSelection ( ) Clears all existing selections.
getAppendDataBoundItems ( ) : boolean
getAutoPostBack ( ) : boolean
getCausesValidation ( ) : boolean
getData ( ) : string Returns the value of the selected item with the lowest cardinal index.
getDataGroupField ( ) : string
getDataTextField ( ) : string
getDataTextFormatString ( ) : string
getDataValueField ( ) : string
getEnableClientScript ( ) : boolean
getHasItems ( ) : boolean
getItemCount ( ) : integer
getItems ( ) : TListItemCollection
getPromptText ( ) : string
getPromptValue ( ) : string
getSelectedIndex ( ) : integer
getSelectedIndices ( ) : array
getSelectedItem ( ) : TListItem | null
getSelectedValue ( ) : string
getSelectedValues ( ) : array
getText ( ) : string
getValidationGroup ( ) : string
loadState ( ) Loads items from viewstate.
onSelectedIndexChanged ( $param ) Raises OnSelectedIndexChanged event when selection is changed.
onTextChanged ( $param ) Raises OnTextChanged event when selection is changed.
renderContents ( $writer ) Renders body content of the list control.
saveState ( ) Saves items into viewstate.
setAppendDataBoundItems ( $value )
setAutoPostBack ( $value ) Sets the value indicating if postback automatically.
setCausesValidation ( $value )
setData ( $value ) Selects an item by the specified value.
setDataGroupField ( $value )
setDataTextField ( $value )
setDataTextFormatString ( $value ) Sets data text format string.
setDataValueField ( $value )
setEnableClientScript ( $value )
setPromptText ( $value )
setPromptValue ( $value )
setSelectedIndex ( $index )
setSelectedIndices ( $indices )
setSelectedValue ( $value ) Sets selection by item value.
setSelectedValues ( $values )
setText ( $value )
setValidationGroup ( $value )

Protected Methods

Method Description
addAttributesToRender ( $writer ) Adds attributes to renderer.
createListItemCollection ( ) : TListItemCollection Creates a collection object to hold list items.
formatDataValue ( $formatString, $value ) : string Formats the text value according to a format string.
getClientClassName ( ) : string Gets the name of the javascript class responsible for performing postback for this control.
getIsMultiSelect ( ) : boolean
getPostBackOptions ( ) : array
getTagName ( ) : string
performDataBinding ( $data ) Performs databinding to populate list items from data source.
renderClientControlScript ( $writer ) Renders the javascript for list control.
renderPrompt ( $writer ) Renders the prompt text, if any.

Private Methods

Method Description
resetCachedSelections ( )

Method Details

addAttributesToRender() protected method

Adds attributes to renderer.
protected addAttributesToRender ( $writer )

addParsedObject() public method

This method adds only {@link TListItem} objects into the {@link getItems Items} collection. All other objects are ignored.
public addParsedObject ( $object )

clearSelection() public method

Clears all existing selections.
public clearSelection ( )

createListItemCollection() protected method

This method may be overriden to create a customized collection.
protected createListItemCollection ( ) : TListItemCollection
return TListItemCollection the collection object

formatDataValue() protected method

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 {@link sprintf}.
protected formatDataValue ( $formatString, $value ) : string
return string the formatted result

getAppendDataBoundItems() public method

public getAppendDataBoundItems ( ) : boolean
return boolean whether performing databind should append items or clear the existing ones. Defaults to false.

getAutoPostBack() public method

public getAutoPostBack ( ) : boolean
return boolean a value indicating whether an automatic postback to the server will occur whenever the user makes change to the list control and then tabs out of it. Defaults to false.

getCausesValidation() public method

public getCausesValidation ( ) : boolean
return boolean whether postback event trigger by this list control will cause input validation, default is true.

getClientClassName() protected method

Derived classes may override this method and return customized js class names.
protected getClientClassName ( ) : string
return string the javascript class name

getData() public method

This method is required by {@link \Prado\IDataRenderer}. It is the same as {@link getSelectedValue()}.
See also: getSelectedValue
Since: 3.1.0
public getData ( ) : string
return string the value of the selected item with the lowest cardinal index, empty if no selection.

getDataGroupField() public method

public getDataGroupField ( ) : string
return string the field of the data source that provides the label of the list item groups

getDataTextField() public method

public getDataTextField ( ) : string
return string the field of the data source that provides the text content of the list items.

getDataTextFormatString() public method

public getDataTextFormatString ( ) : string
return string the formatting string used to control how data bound to the list control is displayed.

getDataValueField() public method

public getDataValueField ( ) : string
return string the field of the data source that provides the value of each list item.

getEnableClientScript() public method

public getEnableClientScript ( ) : boolean
return boolean whether to render javascript.

getHasItems() public method

public getHasItems ( ) : boolean
return boolean whether the list control contains any items.

getIsMultiSelect() protected method

protected getIsMultiSelect ( ) : boolean
return boolean whether this is a multiselect control. Defaults to false.

getItemCount() public method

public getItemCount ( ) : integer
return integer the number of items in the list control

getItems() public method

public getItems ( ) : TListItemCollection
return TListItemCollection the item collection

getPostBackOptions() protected method

protected getPostBackOptions ( ) : array
return array postback options for JS postback code

getPromptText() public method

Since: 3.1.1
public getPromptText ( ) : string
return string the prompt text which is to be displayed as the first list item.

getPromptValue() public method

See also: getPromptText
Since: 3.1.1
public getPromptValue ( ) : string
return string the prompt selection value.

getSelectedIndex() public method

public getSelectedIndex ( ) : integer
return integer the index (zero-based) of the item being selected, -1 if no item is selected.

getSelectedIndices() public method

public getSelectedIndices ( ) : array
return array list of index of items that are selected

getSelectedItem() public method

public getSelectedItem ( ) : TListItem | null
return TListItem | null the selected item with the lowest cardinal index, null if no item is selected.

getSelectedValue() public method

public getSelectedValue ( ) : string
return string the value of the selected item with the lowest cardinal index, empty if no selection

getSelectedValues() public method

public getSelectedValues ( ) : array
return array list of the selected item values (strings)

getTagName() protected method

protected getTagName ( ) : string
return string tag name of the list control

getText() public method

public getText ( ) : string
return string selected value

getValidationGroup() public method

public getValidationGroup ( ) : string
return string the group of validators which the list control causes validation upon postback

loadState() public method

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

onSelectedIndexChanged() public method

This method is invoked when the list control has its selection changed by end-users.
public onSelectedIndexChanged ( $param )

onTextChanged() public method

This method is invoked when the list control has its selection changed by end-users.
public onTextChanged ( $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 )

renderClientControlScript() protected method

Renders the javascript for list control.
protected renderClientControlScript ( $writer )

renderContents() public method

This method renders items contained in the list control as the body content.
public renderContents ( $writer )

renderPrompt() protected method

Renders the prompt text, if any.
Since: 3.1.1
protected renderPrompt ( $writer )

saveState() public method

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

setAppendDataBoundItems() public method

public setAppendDataBoundItems ( $value )

setAutoPostBack() public method

An automatic postback to the server will occur whenever the user makes change to the list control and then tabs out of it.
public setAutoPostBack ( $value )

setCausesValidation() public method

public setCausesValidation ( $value )

setData() public method

This method is required by {@link \Prado\IDataRenderer}. It is the same as {@link setSelectedValue()}.
See also: setSelectedValue
Since: 3.1.0
public setData ( $value )

setDataGroupField() public method

public setDataGroupField ( $value )

setDataTextField() public method

public setDataTextField ( $value )

setDataTextFormatString() public method

The format string is used in {@link TDataValueFormatter::format()} to format the Text property value of each item in the list control.
See also: TDataValueFormatter::format()
public setDataTextFormatString ( $value )

setDataValueField() public method

public setDataValueField ( $value )

setEnableClientScript() public method

public setEnableClientScript ( $value )

setPromptText() public method

Since: 3.1.1
public setPromptText ( $value )

setPromptValue() public method

See also: setPromptText
Since: 3.1.1
public setPromptValue ( $value )

setSelectedIndex() public method

public setSelectedIndex ( $index )

setSelectedIndices() public method

public setSelectedIndices ( $indices )

setSelectedValue() public method

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 setSelectedValue ( $value )

setSelectedValues() public method

public setSelectedValues ( $values )

setText() public method

public setText ( $value )

setValidationGroup() public method

public setValidationGroup ( $value )