| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TBoundColumn class file
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TBoundColumn.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Web.UI.WebControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* TDataGridColumn class file
|
|
|
15 |
*/
|
|
|
16 |
Prado::using('System.Web.UI.WebControls.TDataGridColumn');
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* TBoundColumn class
|
|
|
20 |
*
|
|
|
21 |
* TBoundColumn represents a column that is bound to a field in a data source.
|
|
|
22 |
* The cells in the column will be displayed using the data indexed by
|
|
|
23 |
* {@link setDataField DataField}. You can customize the display by
|
|
|
24 |
* setting {@link setDataFormatString DataFormatString}.
|
|
|
25 |
*
|
|
|
26 |
* If {@link setReadOnly ReadOnly} is false, TBoundColumn will display cells in edit mode
|
|
|
27 |
* with textboxes. Otherwise, a static text is displayed.
|
|
|
28 |
*
|
|
|
29 |
* When a datagrid row is in edit mode, the textbox control in the TBoundColumn
|
|
|
30 |
* can be accessed by one of the following two methods:
|
|
|
31 |
* <code>
|
|
|
32 |
* $datagridItem->BoundColumnID->TextBox
|
|
|
33 |
* $datagridItem->BoundColumnID->Controls[0]
|
|
|
34 |
* </code>
|
|
|
35 |
* The second method is possible because the textbox control created within the
|
|
|
36 |
* datagrid cell is the first child.
|
|
|
37 |
*
|
|
|
38 |
* Since v3.1.0, TBoundColumn has introduced two new properties {@link setItemRenderer ItemRenderer}
|
|
|
39 |
* and {@link setEditItemRenderer EditItemRenderer} which can be used to specify
|
|
|
40 |
* the layout of the datagrid cells in browsing and editing mode.
|
|
|
41 |
* A renderer refers to a control class that is to be instantiated as a control.
|
|
|
42 |
* For more details, see {@link TRepeater} and {@link TDataList}.
|
|
|
43 |
*
|
|
|
44 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
45 |
* @version $Id: TBoundColumn.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
46 |
* @package System.Web.UI.WebControls
|
|
|
47 |
* @since 3.0
|
|
|
48 |
*/
|
|
|
49 |
class TBoundColumn extends TDataGridColumn
|
|
|
50 |
{
|
|
|
51 |
/**
|
|
|
52 |
* @return string the class name for the item cell renderer. Defaults to empty, meaning not set.
|
|
|
53 |
* @since 3.1.0
|
|
|
54 |
*/
|
|
|
55 |
public function getItemRenderer()
|
|
|
56 |
{
|
|
|
57 |
return $this->getViewState('ItemRenderer','');
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Sets the item cell renderer class.
|
|
|
62 |
*
|
|
|
63 |
* If not empty, the class will be used to instantiate as a child control in the item cells of the column.
|
|
|
64 |
*
|
|
|
65 |
* If the class implements {@link IDataRenderer}, the <b>Data</b> property
|
|
|
66 |
* will be set as the data associated with the datagrid cell during databinding.
|
|
|
67 |
* The data can be either the whole data row or a field of the row if
|
|
|
68 |
* {@link getDataField DataField} is not empty. If {@link getDataFormatString DataFormatString}
|
|
|
69 |
* is not empty, the data will be formatted first before passing to the renderer.
|
|
|
70 |
*
|
|
|
71 |
* @param string the renderer class name in namespace format.
|
|
|
72 |
* @since 3.1.0
|
|
|
73 |
*/
|
|
|
74 |
public function setItemRenderer($value)
|
|
|
75 |
{
|
|
|
76 |
$this->setViewState('ItemRenderer',$value,'');
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* @return string the class name for the edit item cell renderer. Defaults to empty, meaning not set.
|
|
|
81 |
* @since 3.1.0
|
|
|
82 |
*/
|
|
|
83 |
public function getEditItemRenderer()
|
|
|
84 |
{
|
|
|
85 |
return $this->getViewState('EditItemRenderer','');
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
/**
|
|
|
89 |
* Sets the edit item cell renderer class.
|
|
|
90 |
*
|
|
|
91 |
* If not empty, the class will be used to instantiate as a child control in the item cell that is in edit mode.
|
|
|
92 |
*
|
|
|
93 |
* If the class implements {@link IDataRenderer}, the <b>Data</b> property
|
|
|
94 |
* will be set as the data associated with the datagrid cell during databinding.
|
|
|
95 |
* The data can be either the whole data row or a field of the row if
|
|
|
96 |
* {@link getDataField DataField} is not empty. If {@link getDataFormatString DataFormatString}
|
|
|
97 |
* is not empty, the data will be formatted first before passing to the renderer.
|
|
|
98 |
*
|
|
|
99 |
* @param string the renderer class name in namespace format.
|
|
|
100 |
* @since 3.1.0
|
|
|
101 |
*/
|
|
|
102 |
public function setEditItemRenderer($value)
|
|
|
103 |
{
|
|
|
104 |
$this->setViewState('EditItemRenderer',$value,'');
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* @return string the field name from the data source to bind to the column
|
|
|
109 |
*/
|
|
|
110 |
public function getDataField()
|
|
|
111 |
{
|
|
|
112 |
return $this->getViewState('DataField','');
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
/**
|
|
|
116 |
* @param string the field name from the data source to bind to the column
|
|
|
117 |
*/
|
|
|
118 |
public function setDataField($value)
|
|
|
119 |
{
|
|
|
120 |
$this->setViewState('DataField',$value,'');
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
/**
|
|
|
124 |
* @return string the formatting string used to control how the bound data will be displayed.
|
|
|
125 |
*/
|
|
|
126 |
public function getDataFormatString()
|
|
|
127 |
{
|
|
|
128 |
return $this->getViewState('DataFormatString','');
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/**
|
|
|
132 |
* @param string the formatting string used to control how the bound data will be displayed.
|
|
|
133 |
*/
|
|
|
134 |
public function setDataFormatString($value)
|
|
|
135 |
{
|
|
|
136 |
$this->setViewState('DataFormatString',$value,'');
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
/**
|
|
|
140 |
* @return boolean whether the items in the column can be edited. Defaults to false.
|
|
|
141 |
*/
|
|
|
142 |
public function getReadOnly()
|
|
|
143 |
{
|
|
|
144 |
return $this->getViewState('ReadOnly',false);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
/**
|
|
|
148 |
* @param boolean whether the items in the column can be edited
|
|
|
149 |
*/
|
|
|
150 |
public function setReadOnly($value)
|
|
|
151 |
{
|
|
|
152 |
$this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
/**
|
|
|
156 |
* Initializes the specified cell to its initial values.
|
|
|
157 |
* This method overrides the parent implementation.
|
|
|
158 |
* It creates a textbox for item in edit mode and the column is not read-only.
|
|
|
159 |
* Otherwise it displays a static text.
|
|
|
160 |
* The caption of the button and the static text are retrieved
|
|
|
161 |
* from the datasource.
|
|
|
162 |
* @param TTableCell the cell to be initialized.
|
|
|
163 |
* @param integer the index to the Columns property that the cell resides in.
|
|
|
164 |
* @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
|
|
|
165 |
*/
|
|
|
166 |
public function initializeCell($cell,$columnIndex,$itemType)
|
|
|
167 |
{
|
|
|
168 |
$item=$cell->getParent();
|
|
|
169 |
switch($itemType)
|
|
|
170 |
{
|
|
|
171 |
case TListItemType::Item:
|
|
|
172 |
case TListItemType::AlternatingItem:
|
|
|
173 |
case TListItemType::SelectedItem:
|
|
|
174 |
if(($classPath=$this->getItemRenderer())!=='')
|
|
|
175 |
{
|
|
|
176 |
$control=Prado::createComponent($classPath);
|
|
|
177 |
if($control instanceof IItemDataRenderer)
|
|
|
178 |
{
|
|
|
179 |
$control->setItemIndex($item->getItemIndex());
|
|
|
180 |
$control->setItemType($item->getItemType());
|
|
|
181 |
}
|
|
|
182 |
$cell->getControls()->add($control);
|
|
|
183 |
}
|
|
|
184 |
else
|
|
|
185 |
$control=$cell;
|
|
|
186 |
$control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
|
|
|
187 |
break;
|
|
|
188 |
case TListItemType::EditItem:
|
|
|
189 |
if(!$this->getReadOnly())
|
|
|
190 |
{
|
|
|
191 |
if(($classPath=$this->getItemRenderer())!=='')
|
|
|
192 |
{
|
|
|
193 |
$control=Prado::createComponent($classPath);
|
|
|
194 |
if($control instanceof IItemDataRenderer)
|
|
|
195 |
{
|
|
|
196 |
$control->setItemIndex($item->getItemIndex());
|
|
|
197 |
$control->setItemType($item->getItemType());
|
|
|
198 |
}
|
|
|
199 |
$cell->getControls()->add($control);
|
|
|
200 |
}
|
|
|
201 |
else
|
|
|
202 |
{
|
|
|
203 |
$control=Prado::createComponent('System.Web.UI.WebControls.TTextBox');
|
|
|
204 |
$cell->getControls()->add($control);
|
|
|
205 |
$cell->registerObject('TextBox',$control);
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
else
|
|
|
209 |
$control=$cell;
|
|
|
210 |
$control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
|
|
|
211 |
break;
|
|
|
212 |
default:
|
|
|
213 |
parent::initializeCell($cell,$columnIndex,$itemType);
|
|
|
214 |
break;
|
|
|
215 |
}
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
/**
|
|
|
219 |
* Databinds a cell in the column.
|
|
|
220 |
* This method is invoked when datagrid performs databinding.
|
|
|
221 |
* It populates the content of the cell with the relevant data from data source.
|
|
|
222 |
*/
|
|
|
223 |
public function dataBindColumn($sender,$param)
|
|
|
224 |
{
|
|
|
225 |
$item=$sender->getNamingContainer();
|
|
|
226 |
$data=$item->getData();
|
|
|
227 |
$formatString=$this->getDataFormatString();
|
|
|
228 |
if(($field=$this->getDataField())!=='')
|
|
|
229 |
$value=$this->formatDataValue($formatString,$this->getDataFieldValue($data,$field));
|
|
|
230 |
else
|
|
|
231 |
$value=$this->formatDataValue($formatString,$data);
|
|
|
232 |
$sender->setData($value);
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|