3 * TLiteralColumn class file
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.pradosoft.com/
7 * @copyright Copyright © 2005-2014 PradoSoft
8 * @license http://www.pradosoft.com/license/
9 * @package System.Web.UI.WebControls
13 * TDataGridColumn class file
15 Prado::using('System.Web.UI.WebControls.TDataGridColumn');
18 * TLiteralColumn class
20 * TLiteralColumn represents a static text column that is bound to a field in a data source.
21 * The cells in the column will be displayed with static texts using the data indexed by
22 * {@link setDataField DataField}. You can customize the display by
23 * setting {@link setDataFormatString DataFormatString}.
25 * If {@link setDataField DataField} is not specified, the cells will be filled
26 * with {@link setText Text}.
28 * If {@link setEncode Encode} is true, the static texts will be HTML-encoded.
30 * @author Qiang Xue <qiang.xue@gmail.com>
31 * @package System.Web.UI.WebControls
34 class TLiteralColumn extends TDataGridColumn
37 * @return string the field name from the data source to bind to the column
39 public function getDataField()
41 return $this->getViewState('DataField','');
45 * @param string the field name from the data source to bind to the column
47 public function setDataField($value)
49 $this->setViewState('DataField',$value,'');
53 * @return string the formatting string used to control how the bound data will be displayed.
55 public function getDataFormatString()
57 return $this->getViewState('DataFormatString','');
61 * @param string the formatting string used to control how the bound data will be displayed.
63 public function setDataFormatString($value)
65 $this->setViewState('DataFormatString',$value,'');
69 * @return string static text to be displayed in the column. Defaults to empty.
71 public function getText()
73 return $this->getViewState('Text','');
77 * @param string static text to be displayed in the column.
79 public function setText($value)
81 $this->setViewState('Text',$value,'');
85 * @return boolean whether the rendered text should be HTML-encoded. Defaults to false.
87 public function getEncode()
89 return $this->getViewState('Encode',false);
93 * @param boolean whether the rendered text should be HTML-encoded.
95 public function setEncode($value)
97 $this->setViewState('Encode',TPropertyValue::ensureBoolean($value),false);
101 * Initializes the specified cell to its initial values.
102 * This method overrides the parent implementation.
103 * @param TTableCell the cell to be initialized.
104 * @param integer the index to the Columns property that the cell resides in.
105 * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
107 public function initializeCell($cell,$columnIndex,$itemType)
109 if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::EditItem || $itemType===TListItemType::SelectedItem)
111 if($this->getDataField()!=='')
113 $cell->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
115 $text=$this->getText();
116 if($this->getEncode())
117 $text=THttpUtility::htmlEncode($text);
118 $cell->setText($text);
122 parent::initializeCell($cell,$columnIndex,$itemType);
126 * Databinds a cell in the column.
127 * This method is invoked when datagrid performs databinding.
128 * It populates the content of the cell with the relevant data from data source.
130 public function dataBindColumn($sender,$param)
132 $item=$sender->getNamingContainer();
133 $data=$item->getData();
134 $formatString=$this->getDataFormatString();
135 if(($field=$this->getDataField())!=='')
136 $value=$this->formatDataValue($formatString,$this->getDataFieldValue($data,$field));
138 $value=$this->formatDataValue($formatString,$data);
139 if($sender instanceof TTableCell)
141 if($this->getEncode())
142 $value=THttpUtility::htmlEncode($value);
143 $sender->setText($value);