PHP Класс Prado\Web\UI\WebControls\TDataGrid

TDataGrid represents a data bound and updatable grid control. To populate data into the datagrid, sets its {@link setDataSource DataSource} to a tabular data source and call {@link dataBind()}. Each row of data will be represented by an item in the {@link getItems Items} collection of the datagrid. An item can be at one of three states: browsing, selected and edit. The state determines how the item will be displayed. For example, if an item is in edit state, it may be displayed as a table row with input text boxes if the columns are of type {@link TBoundColumn}; and if in browsing state, they are displayed as static text. To change the state of an item, set {@link setEditItemIndex EditItemIndex} or {@link setSelectedItemIndex SelectedItemIndex} property. Each datagrid item has a {@link TDataGridItem::getItemType type} which tells the position and state of the item in the datalist. An item in the header of the repeater is of type Header. A body item may be of either Item, AlternatingItem, SelectedItem or EditItem, depending whether the item index is odd or even, whether it is being selected or edited. A datagrid is specified with a list of columns. Each column specifies how the corresponding table column will be displayed. For example, the header/footer text of that column, the cells in that column, and so on. The following column types are currently provided by the framework, - {@link TBoundColumn}, associated with a specific field in datasource and displays the corresponding data. - {@link TEditCommandColumn}, displaying edit/update/cancel command buttons - {@link TButtonColumn}, displaying generic command buttons that may be bound to specific field in datasource. - {@link TDropDownListColumn}, displaying a dropdown list when the item is in edit state - {@link THyperLinkColumn}, displaying a hyperlink that may be bound to specific field in datasource. - {@link TCheckBoxColumn}, displaying a checkbox that may be bound to specific field in datasource. - {@link TTemplateColumn}, displaying content based on templates. There are three ways to specify columns for a datagrid.
  • Automatically generated based on data source. By setting {@link setAutoGenerateColumns AutoGenerateColumns} to true, a list of columns will be automatically generated based on the schema of the data source. Each column corresponds to a column of the data.
  • Specified in template. For example,
  • Manually created in code. Columns can be manipulated via the {@link setColumns Columns} property of the datagrid. For example, $column=new TBoundColumn; $datagrid->Columns[]=$column;
Note, automatically generated columns cannot be accessed via the {@link getColumns Columns} property. TDataGrid supports sorting. If the {@link setAllowSorting AllowSorting} is set to true, a column with nonempty {@link setSortExpression SortExpression} will have its header text displayed as a clickable link button. Clicking on the link button will raise {@link onSortCommand OnSortCommand} event. You can respond to this event, sort the data source according to the event parameter, and then invoke {@link databind()} on the datagrid to show to end users the sorted data. TDataGrid supports paging. If the {@link setAllowPaging AllowPaging} is set to true, a pager will be displayed on top and/or bottom of the table. How the pager will be displayed is determined by the {@link getPagerStyle PagerStyle} property. Clicking on a pager button will raise an {@link onPageIndexChanged OnPageIndexChanged} event. You can respond to this event, specify the page to be displayed by setting {@link setCurrentPageIndex CurrentPageIndex} property, and then invoke {@link databind()} on the datagrid to show to end users a new page of data. TDataGrid supports two kinds of paging. The first one is based on the number of data items in datasource. The number of pages {@link getPageCount PageCount} is calculated based the item number and the {@link setPageSize PageSize} property. The datagrid will manage which section of the data source to be displayed based on the {@link setCurrentPageIndex CurrentPageIndex} property. The second approach calculates the page number based on the {@link setVirtualItemCount VirtualItemCount} property and the {@link setPageSize PageSize} property. The datagrid will always display from the beginning of the datasource up to the number of {@link setPageSize PageSize} data items. This approach is especially useful when the datasource may contain too many data items to be managed by the datagrid efficiently. When the datagrid contains a button control that raises an {@link onCommand OnCommand} event, the event will be bubbled up to the datagrid control. If the event's command name is recognizable by the datagrid control, a corresponding item event will be raised. The following item events will be raised upon a specific command: - OnEditCommand, if CommandName=edit - OnCancelCommand, if CommandName=cancel - OnSelectCommand, if CommandName=select - OnDeleteCommand, if CommandName=delete - OnUpdateCommand, if CommandName=update - onPageIndexChanged, if CommandName=page - OnSortCommand, if CommandName=sort Note, an {@link onItemCommand OnItemCommand} event is raised in addition to the above specific command events. TDataGrid also raises an {@link onItemCreated OnItemCreated} event for every newly created datagrid item. You can respond to this event to customize the content or style of the newly created item. Note, the data bound to the datagrid are reset to null after databinding. There are several ways to access the data associated with a datagrid row: - Access the data in {@link onItemDataBound OnItemDataBound} event - Use {@link getDataKeys DataKeys} to obtain the data key associated with the specified datagrid row and use the key to fetch the corresponding data from some persistent storage such as DB. - Save the data in viewstate and get it back during postbacks.
С версии: 3.0
Автор: Qiang Xue ([email protected])
Наследование: extends TBaseDataList, implements Prado\Web\UI\INamingContainer
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
addParsedObject ( $object ) Adds objects parsed in template to datagrid.
bubbleEvent ( $sender, $param ) : boolean This method overrides parent's implementation to handle {@link onItemCommand OnItemCommand} event which is bubbled from {@link TDataGridItem} child controls.
getAllowSorting ( ) : boolean
getAlternatingItemStyle ( ) : TTableItemStyle
getAutoColumns ( ) : TDataGridColumnCollection
getAutoGenerateColumns ( ) : boolean
getBackImageUrl ( ) : string
getBottomPager ( ) : TDataGridPager
getCaption ( ) : string
getCaptionAlign ( ) : TTableCaptionAlign
getColumns ( ) : TDataGridColumnCollection
getEditItem ( ) : TDataGridItem
getEditItemIndex ( ) : integer
getEditItemStyle ( ) : TTableItemStyle
getEmptyTemplate ( ) : Prado\Web\UI\ITemplate
getFooter ( ) : TDataGridItem
getFooterStyle ( ) : TTableItemStyle
getHeader ( ) : TDataGridItem
getHeaderStyle ( ) : TTableItemStyle
getItemCount ( ) : integer
getItemStyle ( ) : TTableItemStyle
getItems ( ) : TDataGridItemCollection
getPagerStyle ( ) : TDataGridPagerStyle
getSelectedItem ( ) : TDataGridItem
getSelectedItemIndex ( ) : integer
getSelectedItemStyle ( ) : TTableItemStyle
getShowFooter ( ) : boolean
getShowHeader ( ) : boolean
getTableBodyStyle ( ) : TStyle
getTableFootStyle ( ) : TStyle
getTableHeadStyle ( ) : TStyle
getTopPager ( ) : TDataGridPager
loadState ( ) Loads item count information from viewstate.
onCancelCommand ( $param ) Raises OnCancelCommand event.
onDeleteCommand ( $param ) Raises OnDeleteCommand event.
onEditCommand ( $param ) Raises OnEditCommand event.
onItemCommand ( $param ) Raises OnItemCommand event.
onItemCreated ( $param ) Raises OnItemCreated event.
onItemDataBound ( $param ) Raises OnItemDataBound event.
onPageIndexChanged ( $param ) Raises OnPageIndexChanged event.
onPagerCreated ( $param ) Raises OnPagerCreated event.
onSortCommand ( $param ) Raises OnSortCommand event.
onUpdateCommand ( $param ) Raises OnUpdateCommand event.
render ( $writer ) Renders the datagrid.
renderBeginTag ( $writer ) Renders the openning tag for the datagrid control which will render table caption if present.
reset ( ) Clears up all items in the datagrid.
saveState ( ) Saves item count in viewstate.
setAllowSorting ( $value )
setAutoGenerateColumns ( $value )
setBackImageUrl ( $value )
setCaption ( $value )
setCaptionAlign ( $value )
setEditItemIndex ( $value ) Edits an item by its index in {@link getItems Items}.
setEmptyTemplate ( $value )
setSelectedItemIndex ( $value ) Selects an item by its index in {@link getItems Items}.
setShowFooter ( $value )
setShowHeader ( $value )

Защищенные методы

Метод Описание
applyItemStyles ( ) Applies styles to items, header, footer and separators.
buildNextPrevPager ( $pager ) Builds a next-prev pager
buildNumericPager ( $pager ) Builds a numeric pager
buildPager ( $pager ) Builds the pager content based on pager style.
createAutoColumns ( $dataSource ) : TDataGridColumnCollection Automatically generates datagrid columns based on datasource schema
createItem ( $itemIndex, $dataSourceIndex, $itemType ) : TDataGridItem Creates a datagrid item instance based on the item type and index.
createPager ( )
createPagerButton ( $pager, $buttonType, $enabled, $text, $commandName, $commandParameter ) : mixed Creates a pager button.
createStyle ( ) : TTableStyle Creates a style object for the control.
getAutoGenerateColumnName ( ) : string
getTagName ( ) : string
initializeItem ( $item, $columns ) Initializes a datagrid item and cells inside it
performDataBinding ( $data ) Performs databinding to populate datagrid items from data source.
renderTable ( $writer ) Renders the tabular data.
restoreGridFromViewState ( ) Restores datagrid content from viewstate.

Приватные методы

Метод Описание
createItemInternal ( $itemIndex, $dataSourceIndex, $itemType, $dataBind, $dataItem, $columns )
getCellText ( $cell )
groupCells ( ) Merges consecutive cells who have the same text.

Описание методов

addParsedObject() публичный Метод

Datagrid columns are added into {@link getColumns Columns} collection.
public addParsedObject ( $object )

applyItemStyles() защищенный Метод

Item styles are applied in a hierarchical way. Style in higher hierarchy will inherit from styles in lower hierarchy. Starting from the lowest hierarchy, the item styles include item's own style, {@link getItemStyle ItemStyle}, {@link getAlternatingItemStyle AlternatingItemStyle}, {@link getSelectedItemStyle SelectedItemStyle}, and {@link getEditItemStyle EditItemStyle}. Therefore, if background color is set as red in {@link getItemStyle ItemStyle}, {@link getEditItemStyle EditItemStyle} will also have red background color unless it is set to a different value explicitly.
protected applyItemStyles ( )

bubbleEvent() публичный Метод

If the event parameter is {@link TDataGridCommandEventParameter} and the command name is a recognized one, which includes 'select', 'edit', 'delete', 'update', and 'cancel' (case-insensitive), then a corresponding command event is also raised (such as {@link onEditCommand OnEditCommand}). This method should only be used by control developers.
public bubbleEvent ( $sender, $param ) : boolean
Результат boolean whether the event bubbling should stop here.

buildNextPrevPager() защищенный Метод

Builds a next-prev pager
protected buildNextPrevPager ( $pager )

buildNumericPager() защищенный Метод

Builds a numeric pager
protected buildNumericPager ( $pager )

buildPager() защищенный Метод

Builds the pager content based on pager style.
protected buildPager ( $pager )

createAutoColumns() защищенный Метод

Automatically generates datagrid columns based on datasource schema
protected createAutoColumns ( $dataSource ) : TDataGridColumnCollection
Результат TDataGridColumnCollection

createItem() защищенный Метод

Creates a datagrid item instance based on the item type and index.
protected createItem ( $itemIndex, $dataSourceIndex, $itemType ) : TDataGridItem
Результат TDataGridItem created data list item

createPager() защищенный Метод

protected createPager ( )

createPagerButton() защищенный Метод

Depending on the button type, a TLinkButton or a TButton may be created. If it is enabled (clickable), its command name and parameter will also be set. Derived classes may override this method to create additional types of buttons, such as TImageButton.
protected createPagerButton ( $pager, $buttonType, $enabled, $text, $commandName, $commandParameter ) : mixed
Результат mixed the button instance

createStyle() защищенный Метод

This method creates a {@link TTableStyle} to be used by datagrid.
protected createStyle ( ) : TTableStyle
Результат TTableStyle control style to be used

getAllowSorting() публичный Метод

public getAllowSorting ( ) : boolean
Результат boolean whether sorting is enabled. Defaults to false.

getAlternatingItemStyle() публичный Метод

public getAlternatingItemStyle ( ) : TTableItemStyle
Результат TTableItemStyle the style for each alternating item

getAutoColumns() публичный Метод

public getAutoColumns ( ) : TDataGridColumnCollection
Результат TDataGridColumnCollection automatically generated datagrid columns

getAutoGenerateColumnName() защищенный Метод

protected getAutoGenerateColumnName ( ) : string
Результат string Name of the class used in AutoGenerateColumns mode

getAutoGenerateColumns() публичный Метод

public getAutoGenerateColumns ( ) : boolean
Результат boolean whether datagrid columns should be automatically generated. Defaults to true.

getBackImageUrl() публичный Метод

public getBackImageUrl ( ) : string
Результат string the URL of the background image for the datagrid

getBottomPager() публичный Метод

public getBottomPager ( ) : TDataGridPager
Результат TDataGridPager the pager displayed at the bottom of datagrid. It could be null if paging is disabled.

getCaption() публичный Метод

public getCaption ( ) : string
Результат string caption for the datagrid

getCaptionAlign() публичный Метод

public getCaptionAlign ( ) : TTableCaptionAlign
Результат TTableCaptionAlign datagrid caption alignment. Defaults to TTableCaptionAlign::NotSet.

getColumns() публичный Метод

public getColumns ( ) : TDataGridColumnCollection
Результат TDataGridColumnCollection manually specified datagrid columns

getEditItem() публичный Метод

public getEditItem ( ) : TDataGridItem
Результат TDataGridItem the edit item

getEditItemIndex() публичный Метод

public getEditItemIndex ( ) : integer
Результат integer the zero-based index of the edit item in {@link getItems Items}. A value -1 means no item is in edit mode.

getEditItemStyle() публичный Метод

public getEditItemStyle ( ) : TTableItemStyle
Результат TTableItemStyle the style for edit item

getEmptyTemplate() публичный Метод

public getEmptyTemplate ( ) : Prado\Web\UI\ITemplate
Результат Prado\Web\UI\ITemplate the template applied when no data is bound to the datagrid

getFooter() публичный Метод

public getFooter ( ) : TDataGridItem
Результат TDataGridItem the footer item

getFooterStyle() публичный Метод

public getFooterStyle ( ) : TTableItemStyle
Результат TTableItemStyle the style for footer

getHeader() публичный Метод

public getHeader ( ) : TDataGridItem
Результат TDataGridItem the header item

getHeaderStyle() публичный Метод

public getHeaderStyle ( ) : TTableItemStyle
Результат TTableItemStyle the style for header

getItemCount() публичный Метод

public getItemCount ( ) : integer
Результат integer number of items

getItemStyle() публичный Метод

public getItemStyle ( ) : TTableItemStyle
Результат TTableItemStyle the style for every item

getItems() публичный Метод

public getItems ( ) : TDataGridItemCollection
Результат TDataGridItemCollection datagrid item collection

getPagerStyle() публичный Метод

public getPagerStyle ( ) : TDataGridPagerStyle
Результат TDataGridPagerStyle the style for pager

getSelectedItem() публичный Метод

public getSelectedItem ( ) : TDataGridItem
Результат TDataGridItem the selected item, null if no item is selected.

getSelectedItemIndex() публичный Метод

public getSelectedItemIndex ( ) : integer
Результат integer the zero-based index of the selected item in {@link getItems Items}. A value -1 means no item selected.

getSelectedItemStyle() публичный Метод

public getSelectedItemStyle ( ) : TTableItemStyle
Результат TTableItemStyle the style for selected item

getShowFooter() публичный Метод

public getShowFooter ( ) : boolean
Результат boolean whether the footer should be displayed. Defaults to false.

getShowHeader() публичный Метод

public getShowHeader ( ) : boolean
Результат boolean whether the header should be displayed. Defaults to true.

getTableBodyStyle() публичный Метод

С версии: 3.1.1
public getTableBodyStyle ( ) : TStyle
Результат TStyle the style for tbody element, if any

getTableFootStyle() публичный Метод

С версии: 3.1.1
public getTableFootStyle ( ) : TStyle
Результат TStyle the style for tfoot element, if any

getTableHeadStyle() публичный Метод

С версии: 3.1.1
public getTableHeadStyle ( ) : TStyle
Результат TStyle the style for thead element, if any

getTagName() защищенный Метод

protected getTagName ( ) : string
Результат string tag name (table) of the datagrid

getTopPager() публичный Метод

public getTopPager ( ) : TDataGridPager
Результат TDataGridPager the pager displayed at the top of datagrid. It could be null if paging is disabled.

initializeItem() защищенный Метод

Initializes a datagrid item and cells inside it
protected initializeItem ( $item, $columns )

loadState() публичный Метод

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

onCancelCommand() публичный Метод

This method is invoked when a button control raises OnCommand event with cancel command name.
public onCancelCommand ( $param )

onDeleteCommand() публичный Метод

This method is invoked when a button control raises OnCommand event with delete command name.
public onDeleteCommand ( $param )

onEditCommand() публичный Метод

This method is invoked when a button control raises OnCommand event with edit command name.
public onEditCommand ( $param )

onItemCommand() публичный Метод

This method is invoked when a button control raises OnCommand event.
public onItemCommand ( $param )

onItemCreated() публичный Метод

This method is invoked right after a datagrid item is created and before added to page hierarchy.
public onItemCreated ( $param )

onItemDataBound() публичный Метод

This method is invoked for each datagrid item after it performs databinding.
public onItemDataBound ( $param )

onPageIndexChanged() публичный Метод

This method is invoked when current page is changed.
public onPageIndexChanged ( $param )

onPagerCreated() публичный Метод

This method is invoked right after a datagrid pager is created and before added to page hierarchy.
public onPagerCreated ( $param )

onSortCommand() публичный Метод

This method is invoked when a button control raises OnCommand event with sort command name.
public onSortCommand ( $param )

onUpdateCommand() публичный Метод

This method is invoked when a button control raises OnCommand event with update command name.
public onUpdateCommand ( $param )

performDataBinding() защищенный Метод

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

render() публичный Метод

Renders the datagrid.
public render ( $writer )

renderBeginTag() публичный Метод

Renders the openning tag for the datagrid control which will render table caption if present.
public renderBeginTag ( $writer )

renderTable() защищенный Метод

Renders the tabular data.
protected renderTable ( $writer )

reset() публичный Метод

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

restoreGridFromViewState() защищенный Метод

Restores datagrid content from viewstate.
protected restoreGridFromViewState ( )

saveState() публичный Метод

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

setAllowSorting() публичный Метод

public setAllowSorting ( $value )

setAutoGenerateColumns() публичный Метод

public setAutoGenerateColumns ( $value )

setBackImageUrl() публичный Метод

public setBackImageUrl ( $value )

setCaption() публичный Метод

public setCaption ( $value )

setCaptionAlign() публичный Метод

public setCaptionAlign ( $value )

setEditItemIndex() публичный Метод

Previously editting item will change to normal item state. If the index is less than 0, any existing edit item will be cleared up.
public setEditItemIndex ( $value )

setEmptyTemplate() публичный Метод

public setEmptyTemplate ( $value )

setSelectedItemIndex() публичный Метод

Previously selected item will be un-selected. If the item to be selected is already in edit mode, it will remain in edit mode. If the index is less than 0, any existing selection will be cleared up.
public setSelectedItemIndex ( $value )

setShowFooter() публичный Метод

public setShowFooter ( $value )

setShowHeader() публичный Метод

public setShowHeader ( $value )