Class TDataGridColumn
Direct Known Sub-classes:
TDataGridColumn class
TDataGridColumn serves as the base class for the different column types of the TDataGrid control. TDataGridColumn defines the properties and methods that are common among all datagrid column types. In particular, it initializes header and footer cells according to HeaderText and HeaderStyle FooterText and FooterStyle properties. If HeaderImageUrl is specified, the image will be displayed instead in the header cell. The ItemStyle is applied to cells that belong to non-header and -footer datagrid items. When the datagrid enables sorting, if the SortExpression is not empty, the header cell will display a button (linkbutton or imagebutton) that will bubble the sort command event to the datagrid. Since v3.1.0, TDataGridColumn has introduced two new properties HeaderRenderer and FooterRenderer which can be used to specify the layout of header and footer column cells. A renderer refers to a control class that is to be instantiated as a control. For more details, see TRepeater and TDataList. Since v3.1.1, TDataGridColumn has introduced EnableCellGrouping. If a column has this property set true, consecutive cells having the same content in this column will be grouped into one cell. Note, there are some limitations to cell grouping. We determine the cell content according to the cell's TTableCell::getText property. If the text is empty and the cell has some child controls, we will pick up the first control who implements IDataRenderer and obtain its IDataRenderer::getData property. The following datagrid column types are provided by the framework currently, - TBoundColumn, associated with a specific field in datasource and displays the corresponding data.
- TEditCommandColumn, displaying edit/update/cancel command buttons
- TDropDownListColumn, displaying a dropdown list when the item is in edit state
- TButtonColumn, displaying generic command buttons that may be bound to specific field in datasource.
- THyperLinkColumn, displaying a hyperlink that may be bound to specific field in datasource.
- TCheckBoxColumn, displaying a checkbox that may be bound to specific field in datasource.
- TTemplateColumn, displaying content based on templates.
To create your own column class, simply override initializeCell() method, which is the major logic for managing the data and presentation of cells in the column.
Method Summary |
protected
string
|
Formats the text value according to a format string.
|
boolean
|
Returns a value indicating whether this column allows sorting.
|
protected
mixed
|
Fetches the value of the data at the specified field.
|
boolean
|
|
string
|
|
TTableItemStyle
|
|
string
|
|
string
|
|
string
|
|
TTableItemStyle
|
|
string
|
|
string
|
|
TTableItemStyle
|
|
TDataGrid
|
|
string
|
|
protected
mixed
|
Returns a viewstate value.
|
boolean
|
|
void
|
Initializes the column.
|
void
|
Initializes the specified cell to its initial values.
|
protected
void
|
Initializes the footer cell.
|
protected
void
|
Initializes the header cell.
|
void
|
Loads persistent state values.
|
mixed
|
Saves persistent state values.
|
void
|
|
void
|
Sets the column footer cell renderer class.
|
void
|
|
void
|
|
void
|
Sets the column header cell renderer class.
|
void
|
|
void
|
Sets the ID of the column.
|
void
|
|
void
|
|
protected
void
|
setViewState
( string $key, mixed $value, mixed $defaultValue)
Sets a viewstate value.
|
void
|
|
Methods Inherited From TComponent |
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
|
Method Details |
formatDataValue
protected string formatDataValue |
(string $formatString , mixed $value ) |
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 http://www.php.net/sprintf.
Input |
string | $formatString | format string |
mixed | $value | the data to be formatted |
Output |
string
| the formatted result |
Exception |
|
getAllowSorting
public boolean getAllowSorting |
() |
Returns a value indicating whether this column allows sorting.
The column allows sorting only when SortExpression is not empty and the datagrid allows sorting.
Output |
boolean
| whether this column allows sorting |
Exception |
|
getDataFieldValue
protected mixed getDataFieldValue |
(mixed $data , string $field ) |
Fetches the value of the data at the specified field.
If the data is an array, the field is used as an array key. If the data is an of TMap, TList or their derived class, the field is used as a key value. If the data is a component, the field is used as the name of a property.
Input |
mixed | $data | data containing the field of value |
string | $field | the data field |
Output |
mixed
| data value at the specified field |
Exception |
throws | TInvalidDataValueException if the data or the field is invalid. |
|
getEnableCellGrouping
public boolean getEnableCellGrouping |
() |
Output |
boolean
| whether cells having the same content should be grouped together. Defaults to false. |
Exception |
|
getFooterRenderer
public string getFooterRenderer |
() |
Output |
string
| the class name for the column footer cell renderer. Defaults to empty, meaning not set. |
Exception |
|
getFooterStyle
Input |
boolean | $createStyle | whether to create a style if previously not existing |
Output |
TTableItemStyle
| the style for footer |
Exception |
|
getFooterText
public string getFooterText |
() |
Output |
string
| the text to be displayed in the footer of this column |
Exception |
|
getHeaderImageUrl
public string getHeaderImageUrl |
() |
Output |
string
| the url of the image to be displayed in header |
Exception |
|
getHeaderRenderer
public string getHeaderRenderer |
() |
Output |
string
| the class name for the column header cell renderer. Defaults to empty, meaning not set. |
Exception |
|
getHeaderStyle
Input |
boolean | $createStyle | whether to create a style if previously not existing |
Output |
TTableItemStyle
| the style for header |
Exception |
|
getHeaderText
public string getHeaderText |
() |
Output |
string
| the text to be displayed in the header of this column |
Exception |
|
getID
Output |
string
| the ID of the column. |
Exception |
|
getItemStyle
Input |
boolean | $createStyle | whether to create a style if previously not existing |
Output |
TTableItemStyle
| the style for item |
Exception |
|
getOwner
Output |
TDataGrid
| datagrid that owns this column |
Exception |
|
getSortExpression
public string getSortExpression |
() |
Output |
string
| the name of the field or expression for sorting |
Exception |
|
getViewState
protected mixed getViewState |
(string $key , mixed $defaultValue ) |
Returns a viewstate value.
Input |
string | $key | the name of the viewstate value to be returned |
mixed | $defaultValue | the default value. If $key is not found in viewstate, $defaultValue will be returned |
Output |
mixed
| the viewstate value corresponding to $key |
Exception |
|
getVisible
public boolean getVisible |
(mixed $checkParents ) |
Input |
mixed | $checkParents | |
Output |
boolean
| whether the column is visible. Defaults to true. |
Exception |
|
initialize
public void initialize |
() |
Initializes the column.
This method is invoked by TDataGrid when the column is about to be used to initialize datagrid items. Derived classes may override this method to do additional initialization.
|
initializeCell
public void initializeCell |
(TTableCell $cell , integer $columnIndex , string $itemType ) |
Initializes the specified cell to its initial values.
The default implementation sets the content of header and footer cells. If sorting is enabled by the grid and sort expression is specified in the column, the header cell will show a link/image button. Otherwise, the header/footer cell will only show static text/image. This method can be overriden to provide customized intialization to column cells.
Input |
TTableCell | $cell | the cell to be initialized. |
integer | $columnIndex | the index to the Columns property that the cell resides in. |
string | $itemType | the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem) |
Output |
Exception |
|
initializeFooterCell
protected void initializeFooterCell |
(TTableCell $cell , integer $columnIndex ) |
Initializes the footer cell.
This method attempts to use FooterRenderer to instantiate the footer cell. If that is not available, it will populate the cell with a text string specified by getFooterImageUrl
Input |
TTableCell | $cell | the cell to be initialized |
integer | $columnIndex | the index to the Columns property that the cell resides in. |
Output |
Exception |
|
initializeHeaderCell
protected void initializeHeaderCell |
(TTableCell $cell , integer $columnIndex ) |
Initializes the header cell.
This method attempts to use HeaderRenderer to instantiate the header cell. If that is not available, it will populate the cell with an image or a text string, depending on HeaderImageUrl and HeaderText property values. If the column allows sorting, image or text will be created as a button which issues Sort command upon user click.
Input |
TTableCell | $cell | the cell to be initialized |
integer | $columnIndex | the index to the Columns property that the cell resides in. |
Output |
Exception |
|
loadState
public void loadState |
(mixed $state ) |
Loads persistent state values.
Input |
mixed | $state | state values |
Output |
Exception |
|
saveState
public mixed saveState |
() |
Saves persistent state values.
Output |
mixed
| values to be saved |
Exception |
|
setEnableCellGrouping
public void setEnableCellGrouping |
(boolean $value ) |
Input |
boolean | $value | whether cells having the same content should be grouped together. |
Output |
Exception |
|
setFooterRenderer
public void setFooterRenderer |
(string $value ) |
Sets the column footer cell renderer class.
If not empty, the class will be used to instantiate as a child control in the column footer cell. If the class implements IDataRenderer, the Data property will be set as the FooterText.
Input |
string | $value | the renderer class name in namespace format. |
Output |
Exception |
|
setFooterText
public void setFooterText |
(string $value ) |
Input |
string | $value | text to be displayed in the footer of this column |
Output |
Exception |
|
setHeaderImageUrl
public void setHeaderImageUrl |
(string $value ) |
Input |
string | $value | the url of the image to be displayed in header |
Output |
Exception |
|
setHeaderRenderer
public void setHeaderRenderer |
(string $value ) |
Sets the column header cell renderer class.
If not empty, the class will be used to instantiate as a child control in the column header cell. If the class implements IDataRenderer, the Data property will be set as the FooterText.
Input |
string | $value | the renderer class name in namespace format. |
Output |
Exception |
|
setHeaderText
public void setHeaderText |
(string $value ) |
Input |
string | $value | text to be displayed in the header of this column |
Output |
Exception |
|
setID
public void setID |
(string $value ) |
Sets the ID of the column.
By explicitly specifying the column ID, one can access the column by $templateControl->ColumnID.
Input |
string | $value | the ID of the column. |
Output |
Exception |
throws | TInvalidDataValueException if the ID is of bad format |
|
setOwner
public void setOwner |
(TDataGrid $value ) |
Input |
TDataGrid | $value | datagrid object that owns this column |
Output |
Exception |
|
setSortExpression
public void setSortExpression |
(string $value ) |
Input |
string | $value | the name of the field or expression for sorting |
Output |
Exception |
|
setViewState
protected void setViewState |
(string $key , mixed $value , mixed $defaultValue ) |
Sets a viewstate value.
Make sure that the viewstate value must be serializable and unserializable.
Input |
string | $key | the name of the viewstate value |
mixed | $value | the viewstate value to be set |
mixed | $defaultValue | default value. If $value===$defaultValue, the item will be cleared from the viewstate. |
Output |
Exception |
|
setVisible
public void setVisible |
(boolean $value ) |
Input |
boolean | $value | whether the column is visible |
Output |
Exception |
|
|