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
Afficher le fichier Open project: pradosoft/prado Class Usage Examples

Méthodes publiques

Méthode 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 )

Méthodes protégées

Méthode 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

Méthode Description
resetCachedSelections ( )

Method Details

addAttributesToRender() protected méthode

Adds attributes to renderer.
protected addAttributesToRender ( $writer )

addParsedObject() public méthode

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

clearSelection() public méthode

Clears all existing selections.
public clearSelection ( )

createListItemCollection() protected méthode

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

formatDataValue() protected méthode

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
Résultat string the formatted result

getAppendDataBoundItems() public méthode

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

getAutoPostBack() public méthode

public getAutoPostBack ( ) : boolean
Résultat 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 méthode

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

getClientClassName() protected méthode

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

getData() public méthode

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
Résultat string the value of the selected item with the lowest cardinal index, empty if no selection.

getDataGroupField() public méthode

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

getDataTextField() public méthode

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

getDataTextFormatString() public méthode

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

getDataValueField() public méthode

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

getEnableClientScript() public méthode

public getEnableClientScript ( ) : boolean
Résultat boolean whether to render javascript.

getHasItems() public méthode

public getHasItems ( ) : boolean
Résultat boolean whether the list control contains any items.

getIsMultiSelect() protected méthode

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

getItemCount() public méthode

public getItemCount ( ) : integer
Résultat integer the number of items in the list control

getItems() public méthode

public getItems ( ) : TListItemCollection
Résultat TListItemCollection the item collection

getPostBackOptions() protected méthode

protected getPostBackOptions ( ) : array
Résultat array postback options for JS postback code

getPromptText() public méthode

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

getPromptValue() public méthode

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

getSelectedIndex() public méthode

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

getSelectedIndices() public méthode

public getSelectedIndices ( ) : array
Résultat array list of index of items that are selected

getSelectedItem() public méthode

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

getSelectedValue() public méthode

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

getSelectedValues() public méthode

public getSelectedValues ( ) : array
Résultat array list of the selected item values (strings)

getTagName() protected méthode

protected getTagName ( ) : string
Résultat string tag name of the list control

getText() public méthode

public getText ( ) : string
Résultat string selected value

getValidationGroup() public méthode

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

loadState() public méthode

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

onSelectedIndexChanged() public méthode

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

onTextChanged() public méthode

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

performDataBinding() protected méthode

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

renderClientControlScript() protected méthode

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

renderContents() public méthode

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

renderPrompt() protected méthode

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

saveState() public méthode

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

setAppendDataBoundItems() public méthode

public setAppendDataBoundItems ( $value )

setAutoPostBack() public méthode

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 méthode

public setCausesValidation ( $value )

setData() public méthode

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 méthode

public setDataGroupField ( $value )

setDataTextField() public méthode

public setDataTextField ( $value )

setDataTextFormatString() public méthode

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 méthode

public setDataValueField ( $value )

setEnableClientScript() public méthode

public setEnableClientScript ( $value )

setPromptText() public méthode

Since: 3.1.1
public setPromptText ( $value )

setPromptValue() public méthode

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

setSelectedIndex() public méthode

public setSelectedIndex ( $index )

setSelectedIndices() public méthode

public setSelectedIndices ( $indices )

setSelectedValue() public méthode

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 méthode

public setSelectedValues ( $values )

setText() public méthode

public setText ( $value )

setValidationGroup() public méthode

public setValidationGroup ( $value )