3 * TLiteralColumn class file
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.pradosoft.com/
7 * @copyright Copyright © 2005-2013 PradoSoft
8 * @license http://www.pradosoft.com/license/
9 * @version $Id: TLiteralColumn.php 1397 2006-09-07 07:55:53Z wei $
10 * @package System.Web.UI.WebControls
14 * TDataGridColumn class file
16 Prado::using('System.Web.UI.WebControls.TDataGridColumn');
19 * TLiteralColumn class
21 * TLiteralColumn represents a static text column that is bound to a field in a data source.
22 * The cells in the column will be displayed with static texts using the data indexed by
23 * {@link setDataField DataField}. You can customize the display by
24 * setting {@link setDataFormatString DataFormatString}.
26 * If {@link setDataField DataField} is not specified, the cells will be filled
27 * with {@link setText Text}.
29 * If {@link setEncode Encode} is true, the static texts will be HTML-encoded.
31 * @author Qiang Xue <qiang.xue@gmail.com>
32 * @version $Id: TLiteralColumn.php 1397 2006-09-07 07:55:53Z wei $
33 * @package System.Web.UI.WebControls
36 class TLiteralColumn extends TDataGridColumn
39 * @return string the field name from the data source to bind to the column
41 public function getDataField()
43 return $this->getViewState('DataField','');
47 * @param string the field name from the data source to bind to the column
49 public function setDataField($value)
51 $this->setViewState('DataField',$value,'');
55 * @return string the formatting string used to control how the bound data will be displayed.
57 public function getDataFormatString()
59 return $this->getViewState('DataFormatString','');
63 * @param string the formatting string used to control how the bound data will be displayed.
65 public function setDataFormatString($value)
67 $this->setViewState('DataFormatString',$value,'');
71 * @return string static text to be displayed in the column. Defaults to empty.
73 public function getText()
75 return $this->getViewState('Text','');
79 * @param string static text to be displayed in the column.
81 public function setText($value)
83 $this->setViewState('Text',$value,'');
87 * @return boolean whether the rendered text should be HTML-encoded. Defaults to false.
89 public function getEncode()
91 return $this->getViewState('Encode',false);
95 * @param boolean whether the rendered text should be HTML-encoded.
97 public function setEncode($value)
99 $this->setViewState('Encode',TPropertyValue::ensureBoolean($value),false);
103 * Initializes the specified cell to its initial values.
104 * This method overrides the parent implementation.
105 * @param TTableCell the cell to be initialized.
106 * @param integer the index to the Columns property that the cell resides in.
107 * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
109 public function initializeCell($cell,$columnIndex,$itemType)
111 if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::EditItem || $itemType===TListItemType::SelectedItem)
113 if($this->getDataField()!=='')
114 $cell->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
117 if(($dataField=$this->getDataField())!=='')
118 $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
121 $text=$this->getText();
122 if($this->getEncode())
123 $text=THttpUtility::htmlEncode($text);
124 $cell->setText($text);
129 parent::initializeCell($cell,$columnIndex,$itemType);
133 * Databinds a cell in the column.
134 * This method is invoked when datagrid performs databinding.
135 * It populates the content of the cell with the relevant data from data source.
137 public function dataBindColumn($sender,$param)
139 $item=$sender->getNamingContainer();
140 $data=$item->getData();
141 $formatString=$this->getDataFormatString();
142 if(($field=$this->getDataField())!=='')
143 $value=$this->formatDataValue($formatString,$this->getDataFieldValue($data,$field));
145 $value=$this->formatDataValue($formatString,$data);
146 if($sender instanceof TTableCell)
148 if($this->getEncode())
149 $value=THttpUtility::htmlEncode($value);
150 $sender->setText($value);