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
파일 보기 프로젝트 열기: pradosoft/prado 1 사용 예제들

공개 메소드들

메소드 설명
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 )