Yii2 Bootstrap 3
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.5 KiB

12 years ago
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\grid;
12 years ago
use Closure;
use yii\base\Object;
use yii\helpers\Html;
/**
* 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 = [];
public $headerOptions = [];
12 years ago
/**
* @var array|\Closure
*/
public $contentOptions = [];
public $footerOptions = [];
12 years ago
/**
* @var array the HTML attributes for the filter cell tag.
*/
public $filterOptions=[];
12 years ago
/**
* 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.
* @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
*/
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
}
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.
11 years ago
* The default implementation simply renders [[header]].
12 years ago
* 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.
11 years ago
* The default implementation simply renders [[footer]].
12 years ago
* 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.
* @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
*/
protected function renderDataCellContent($model, $index)
12 years ago
{
if ($this->content !== null) {
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;
}
}