You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.6 KiB
143 lines
3.6 KiB
12 years ago
|
<?php
|
||
|
/**
|
||
|
* @link http://www.yiiframework.com/
|
||
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
||
|
* @license http://www.yiiframework.com/license/
|
||
|
*/
|
||
|
|
||
12 years ago
|
namespace yii\grid;
|
||
12 years ago
|
|
||
|
use Closure;
|
||
|
use yii\base\Object;
|
||
|
use yii\helpers\Html;
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Column is the base class of all [[GridView]] column classes.
|
||
12 years ago
|
*
|
||
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||
|
* @since 2.0
|
||
|
*/
|
||
|
class Column extends Object
|
||
|
{
|
||
|
/**
|
||
|
* @var GridView the grid view object that owns this column.
|
||
|
*/
|
||
|
public $grid;
|
||
|
/**
|
||
|
* @var string the header cell content. Note that it will not be HTML-encoded.
|
||
|
*/
|
||
|
public $header;
|
||
|
/**
|
||
|
* @var string the footer cell content. Note that it will not be HTML-encoded.
|
||
|
*/
|
||
|
public $footer;
|
||
|
/**
|
||
|
* @var callable
|
||
|
*/
|
||
|
public $content;
|
||
|
/**
|
||
|
* @var boolean whether this column is visible. Defaults to true.
|
||
|
*/
|
||
|
public $visible = true;
|
||
|
public $options = array();
|
||
|
public $headerOptions = array();
|
||
|
/**
|
||
|
* @var array|\Closure
|
||
|
*/
|
||
12 years ago
|
public $contentOptions = array();
|
||
12 years ago
|
public $footerOptions = array();
|
||
|
/**
|
||
|
* @var array the HTML attributes for the filter cell tag.
|
||
|
*/
|
||
|
public $filterOptions=array();
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Renders the header cell.
|
||
|
*/
|
||
|
public function renderHeaderCell()
|
||
|
{
|
||
|
return Html::tag('th', $this->renderHeaderCellContent(), $this->headerOptions);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Renders the footer cell.
|
||
|
*/
|
||
|
public function renderFooterCell()
|
||
|
{
|
||
|
return Html::tag('td', $this->renderFooterCellContent(), $this->footerOptions);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Renders a data cell.
|
||
12 years ago
|
* @param mixed $model the data model being rendered
|
||
12 years ago
|
* @param integer $index the zero-based index of the data item among the item array returned by [[dataProvider]].
|
||
|
* @return string the rendering result
|
||
|
*/
|
||
12 years ago
|
public function renderDataCell($model, $index)
|
||
12 years ago
|
{
|
||
12 years ago
|
if ($this->contentOptions instanceof Closure) {
|
||
|
$options = call_user_func($this->contentOptions, $model, $index, $this);
|
||
12 years ago
|
} else {
|
||
12 years ago
|
$options = $this->contentOptions;
|
||
12 years ago
|
}
|
||
12 years ago
|
return Html::tag('td', $this->renderDataCellContent($model, $index), $options);
|
||
12 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Renders the filter cell.
|
||
|
*/
|
||
|
public function renderFilterCell()
|
||
|
{
|
||
|
return Html::tag('td', $this->renderFilterCellContent(), $this->filterOptions);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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.
|
||
|
* @return string the rendering result
|
||
|
*/
|
||
|
protected function renderHeaderCellContent()
|
||
|
{
|
||
|
return trim($this->header) !== '' ? $this->header : $this->grid->emptyCell;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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.
|
||
|
* @return string the rendering result
|
||
|
*/
|
||
|
protected function renderFooterCellContent()
|
||
|
{
|
||
|
return trim($this->footer) !== '' ? $this->footer : $this->grid->emptyCell;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Renders the data cell content.
|
||
12 years ago
|
* @param mixed $model the data model
|
||
|
* @param integer $index the zero-based index of the data model among the models array returned by [[dataProvider]].
|
||
12 years ago
|
* @return string the rendering result
|
||
|
*/
|
||
12 years ago
|
protected function renderDataCellContent($model, $index)
|
||
12 years ago
|
{
|
||
|
if ($this->content !== null) {
|
||
12 years ago
|
return call_user_func($this->content, $model, $index, $this);
|
||
12 years ago
|
} else {
|
||
|
return $this->grid->emptyCell;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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).
|
||
|
* @return string the rendering result
|
||
|
*/
|
||
|
protected function renderFilterCellContent()
|
||
|
{
|
||
|
return $this->grid->emptyCell;
|
||
|
}
|
||
|
}
|