13 Yii::import(
'booster.widgets.TbGridView');
81 if (!empty($this->extraRowColumns)) {
82 foreach ($this->columns as $column) {
83 if ($column instanceof CDataColumn && in_array($column->name, $this->extraRowColumns)) {
84 $column->filterHtmlOptions = array(
'style' =>
'display:none');
85 $column->filter =
false;
92 if (isset($this->extraRowHtmlOptions[
'class']) && !empty($this->extraRowCssClass)) {
106 if($this->ajaxUpdate===
false)
109 $ajaxUpdate=array_unique(preg_split(
'/\s*,\s*/',$this->ajaxUpdate.
','.$id,-1,PREG_SPLIT_NO_EMPTY));
111 'ajaxUpdate'=>$ajaxUpdate,
112 'ajaxVar'=>$this->ajaxVar,
113 'pagerClass'=>$this->pagerCssClass,
114 'loadingClass'=>$this->loadingCssClass,
115 'filterClass'=>$this->filterCssClass,
116 'tableClass'=>$this->itemsCssClass,
117 'selectableRows'=>$this->selectableRows,
118 'enableHistory'=>$this->enableHistory,
119 'updateSelector'=>$this->updateSelector,
120 'filterSelector'=>$this->filterSelector
122 if($this->ajaxUrl!==null)
123 $options[
'url']=CHtml::normalizeUrl($this->ajaxUrl);
124 if($this->ajaxType!==null)
125 $options[
'ajaxType']=strtoupper($this->ajaxType);
126 if($this->enablePagination)
127 $options[
'pageVar']=$this->dataProvider->getPagination()->pageVar;
128 foreach(array(
'beforeAjaxUpdate',
'afterAjaxUpdate',
'ajaxUpdateError',
'selectionChanged') as $event)
130 if($this->$event!==null)
132 if($this->$event instanceof CJavaScriptExpression)
133 $options[$event]=$this->$event;
135 $options[$event]=
new CJavaScriptExpression($this->$event);
139 $options=CJavaScript::encode($options);
140 $cs=Yii::app()->getClientScript();
141 $cs->registerCoreScript(
'jquery');
142 $cs->registerCoreScript(
'bbq');
143 if($this->enableHistory)
144 $cs->registerCoreScript(
'history');
146 $cs->registerPackage(
'group-grid-view');
147 $cs->registerScript(__CLASS__.
'#'.$id,
"jQuery('#$id').yiiGroupGridView($options);");
155 if (!empty($this->mergeColumns) || !empty($this->extraRowColumns)) {
167 $data = $this->dataProvider->getData();
168 if (count(
$data) == 0) {
172 if (!is_array($this->mergeColumns)) {
173 $this->mergeColumns = array($this->mergeColumns);
175 if (!is_array($this->extraRowColumns)) {
176 $this->extraRowColumns = array($this->extraRowColumns);
180 $groupColumns = array_unique(array_merge($this->mergeColumns, $this->extraRowColumns));
181 foreach ($groupColumns as $key => $colName) {
182 foreach ($this->columns as $column) {
183 if (property_exists($column,
'name') && $column->name == $colName) {
184 $groupColumns[$key] = $column;
193 foreach ($lastStored as $colName => $value) {
194 $lastStored[$colName] = array(
202 $rowcount = count(
$data);
203 for (
$i = 1;
$i < $rowcount;
$i++) {
208 $changedColumns = array();
209 foreach ($current as $colName => $curValue) {
210 if ($curValue != $lastStored[$colName][
'value']) {
211 $changedColumns[] = $colName;
219 $saveChangeForAllColumns = (count(array_intersect($changedColumns, $this->extraRowColumns)) > 0);
225 $changeOccurred =
false;
226 foreach ($current as $colName => $curValue) {
228 $valueChanged = ($curValue != $lastStored[$colName][
'value']);
230 $saveChange = $valueChanged || ($changeOccurred && $this->mergeType ==
self::MERGE_NESTED);
232 if ($saveChangeForAllColumns || $saveChange) {
233 $changeOccurred =
true;
236 $prevIndex = $lastStored[$colName][
'index'];
237 $this->_changes[$prevIndex][
'columns'][$colName] = $lastStored[$colName];
238 if (!isset($this->_changes[$prevIndex][
'count'])) {
239 $this->_changes[$prevIndex][
'count'] = $lastStored[$colName][
'count'];
243 $lastStored[$colName] = array(
244 'value' => $curValue,
250 $lastStored[$colName][
'count']++;
256 foreach ($lastStored as $colName => $v) {
257 $prevIndex = $v[
'index'];
258 $this->_changes[$prevIndex][
'columns'][$colName] = $v;
260 if (!isset($this->_changes[$prevIndex][
'count'])) {
261 $this->_changes[$prevIndex][
'count'] = $v[
'count'];
274 if ($this->_changes && array_key_exists($row, $this->_changes)) {
275 $change = $this->_changes[$row];
277 $columnsInExtra = array_intersect(array_keys($change[
'columns']), $this->extraRowColumns);
278 if (count($columnsInExtra) > 0) {
284 if ($this->rowCssClassExpression !== null) {
285 $data = $this->dataProvider->data[$row];
286 echo
'<tr class="' . $this->evaluateExpression(
287 $this->rowCssClassExpression,
288 array(
'row' => $row,
'data' =>
$data)
290 }
else if (is_array($this->rowCssClass) && ($n = count($this->rowCssClass)) > 0) {
291 echo
'<tr class="' . $this->rowCssClass[$row % $n] .
'">';
297 if (!$this->_changes) {
298 foreach ($this->columns as $column) {
299 $column->renderDataCell($row);
302 foreach ($this->columns as $column) {
303 $isGroupColumn = property_exists($column,
'name') && in_array($column->name, $this->mergeColumns);
304 if (!$isGroupColumn) {
305 $column->renderDataCell($row);
309 $isChangedColumn = $change && array_key_exists($column->name, $change[
'columns']);
312 switch ($this->mergeType) {
313 case self::MERGE_SIMPLE:
314 case self::MERGE_NESTED:
315 if ($isChangedColumn) {
316 $options = $column->htmlOptions;
317 $column->htmlOptions[
'rowspan'] = $change[
'columns'][$column->name][
'count'];
318 $column->htmlOptions[
'class'] =
'merge';
319 $style = isset($column->htmlOptions[
'style']) ? $column->htmlOptions[
'style'] :
'';
321 $column->renderDataCell($row);
322 $column->htmlOptions = $options;
326 case self::MERGE_FIRSTROW:
327 if ($isChangedColumn) {
328 $column->renderDataCell($row);
353 foreach ($columns as $column) {
356 } elseif (is_string($column)) {
357 if (is_array(
$data) && array_key_exists($column,
$data)) {
358 $result[$column] =
$data[$column];
359 } elseif (
$data instanceOf CActiveRecord &&
$data->hasAttribute($column)) {
360 $result[$column] =
$data->getAttribute($column);
362 throw new CException(
'Column or attribute "' . $column .
'" not found!');
366 return isset($result) ? $result :
false;
378 $data = $this->dataProvider->data[$beforeRow];
379 if ($this->extraRowExpression) {
380 $content = $this->evaluateExpression(
381 $this->extraRowExpression,
382 array(
'data' =>
$data,
'row' => $beforeRow,
'values' => $change[
'columns'])
386 foreach ($columnsInExtra as $c) {
387 $values[] = $change[
'columns'][$c][
'value'];
390 $content =
'<strong>' . implode(
' :: ', $values) .
'</strong>';
393 $colspan = count($this->columns);
395 echo
'<tr class="extrarow">';
396 $this->extraRowHtmlOptions[
'colspan'] = $colspan;
397 echo CHtml::openTag(
'td', $this->extraRowHtmlOptions);
399 echo CHtml::closeTag(
'td');
414 if ($column->value !== null) {
415 $value = $column->evaluateExpression($column->value, array(
'data' =>
$data,
'row' => $row));
416 }
else if ($column->name !== null) {
420 return !isset($value)
421 ? $column->grid->nullDisplay
422 : $column->grid->getFormatter()->format(