CGridColumn.php
5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/**
* CGridColumn class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2011 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/**
* CGridColumn is the base class for all grid view column classes.
*
* A CGridColumn object represents the specification for rendering the cells in
* a particular grid view column.
*
* In a column, there is one header cell, multiple data cells, and an optional footer cell.
* Child classes may override {@link renderHeaderCellContent}, {@link renderDataCellContent}
* and {@link renderFooterCellContent} to customize how these cells are rendered.
*
* @property boolean $hasFooter Whether this column has a footer cell.
* This is determined based on whether {@link footer} is set.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package zii.widgets.grid
* @since 1.1
*/
abstract class CGridColumn extends CComponent
{
/**
* @var string the ID of this column. This value should be unique among all grid view columns.
* If this is not set, it will be assigned one automatically.
*/
public $id;
/**
* @var CGridView the grid view object that owns this column.
*/
public $grid;
/**
* @var string the header cell text. Note that it will not be HTML-encoded.
*/
public $header;
/**
* @var string the footer cell text. Note that it will not be HTML-encoded.
*/
public $footer;
/**
* @var boolean whether this column is visible. Defaults to true.
*/
public $visible=true;
/**
* @var string a PHP expression that is evaluated for every data cell and whose result
* is used as the CSS class name for the data cell. In this expression, the variable
* <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
* and <code>$this</code> the column object.
*/
public $cssClassExpression;
/**
* @var array the HTML options for the data cell tags.
*/
public $htmlOptions=array();
/**
* @var array the HTML options for the filter cell tag.
*/
public $filterHtmlOptions=array();
/**
* @var array the HTML options for the header cell tag.
*/
public $headerHtmlOptions=array();
/**
* @var array the HTML options for the footer cell tag.
*/
public $footerHtmlOptions=array();
/**
* Constructor.
* @param CGridView $grid the grid view that owns this column.
*/
public function __construct($grid)
{
$this->grid=$grid;
}
/**
* Initializes the column.
* This method is invoked by the grid view when it initializes itself before rendering.
* You may override this method to prepare the column for rendering.
*/
public function init()
{
}
/**
* @return boolean whether this column has a footer cell.
* This is determined based on whether {@link footer} is set.
*/
public function getHasFooter()
{
return $this->footer!==null;
}
/**
* Renders the filter cell.
* @since 1.1.1
*/
public function renderFilterCell()
{
echo CHtml::openTag('td',$this->filterHtmlOptions);
$this->renderFilterCellContent();
echo "</td>";
}
/**
* Renders the header cell.
*/
public function renderHeaderCell()
{
$this->headerHtmlOptions['id']=$this->id;
echo CHtml::openTag('th',$this->headerHtmlOptions);
$this->renderHeaderCellContent();
echo "</th>";
}
/**
* Renders a data cell.
* @param integer $row the row number (zero-based)
*/
public function renderDataCell($row)
{
$data=$this->grid->dataProvider->data[$row];
$options=$this->htmlOptions;
if($this->cssClassExpression!==null)
{
$class=$this->evaluateExpression($this->cssClassExpression,array('row'=>$row,'data'=>$data));
if(!empty($class))
{
if(isset($options['class']))
$options['class'].=' '.$class;
else
$options['class']=$class;
}
}
echo CHtml::openTag('td',$options);
$this->renderDataCellContent($row,$data);
echo '</td>';
}
/**
* Renders the footer cell.
*/
public function renderFooterCell()
{
echo CHtml::openTag('td',$this->footerHtmlOptions);
$this->renderFooterCellContent();
echo '</td>';
}
/**
* Renders the header cell content.
* The default implementation simply renders {@link header}.
* This method may be overridden to customize the rendering of the header cell.
*/
protected function renderHeaderCellContent()
{
echo trim($this->header)!=='' ? $this->header : $this->grid->blankDisplay;
}
/**
* Renders the footer cell content.
* The default implementation simply renders {@link footer}.
* This method may be overridden to customize the rendering of the footer cell.
*/
protected function renderFooterCellContent()
{
echo trim($this->footer)!=='' ? $this->footer : $this->grid->blankDisplay;
}
/**
* Renders the data cell content.
* This method SHOULD be overridden to customize the rendering of the data cell.
* @param integer $row the row number (zero-based)
* @param mixed $data the data associated with the row
*/
protected function renderDataCellContent($row,$data)
{
echo $this->grid->blankDisplay;
}
/**
* Renders the filter cell content.
* The default implementation simply renders a space.
* This method may be overridden to customize the rendering of the filter cell (if any).
* @since 1.1.1
*/
protected function renderFilterCellContent()
{
echo $this->grid->blankDisplay;
}
}