扩展CGridView的footer [ 新手入门 ]
通过设置footerHtmlOptions的colspan属性不起作用,有多少列还是输出了多少个单元格,改了下,大家看看代码还可以优化吗?
<?php
Yii::import('zii.widgets.grid.CGridView');
class MyCGridView extends CGridView
{
public function renderTableFooter()
{
$hasFilter=$this->filter!==null && $this->filterPosition===self::FILTER_POS_FOOTER;
$hasFooter=$this->getHasFooter();
if($hasFilter || $hasFooter)
{
echo "<tfoot>\n";
if($hasFooter)
{
echo "<tr>\n";
$array_reverse = array_reverse($this->columns,true);
$array_colspan = array();
$colspan = 1;
foreach($array_reverse as $key => $column)
{
if (!$column -> getHasFooter())
$colspan++;
else
{
$array_colspan[$key] = $colspan;
$colspan = 1;
}
}
if ($this->dataProvider->totalItemCount > 0)
{
foreach($this->columns as $key => $column)
{
if ($column -> getHasFooter())
{
$column->footerHtmlOptions = array('colspan' => $array_colspan[$key]);
$column->renderFooterCell();
}
}
}
echo "</tr>\n";
}
if($hasFilter)
$this->renderFilter();
echo "</tfoot>\n";
}
}
}
?>
共 14 条回复
-
wanyun_liu 回复于 2011-11-24 12:28 举报
不错啊。。。。。。。。。。。。。。。
-
根據版主的寫法改良的:
public function renderTableFooter() { $hasFilter=$this->filter!==null && $this->filterPosition===self::FILTER_POS_FOOTER; $hasFooter=$this->getHasFooter(); if($hasFilter || $hasFooter) { echo "<tfoot>\n"; if($hasFooter) { echo "<tr>\n"; $count = 0; foreach($this->columns as $column) { if($count == 0) $column->renderFooterCell(); else $count--; if($column -> getHasFooter()) $count = $column->footerHtmlOptions['colspan'] -1; } echo "</tr>\n"; } if($hasFilter) $this->renderFilter(); echo "</tfoot>\n"; } }
skye 深圳
注册时间:2011-04-12
最后登录:2013-06-18
在线时长:0小时0分
最后登录:2013-06-18
在线时长:0小时0分
- 粉丝2
- 金钱575
- 威望0
- 积分575