skye 2011-04-27 19:15:37 5693次浏览 14条回复 0 0 0

通过设置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";
     }
    }
}

?>
您需要登录后才可以回复。登录 | 立即注册