Commit 1398de3f by Qiang Xue

Renamed DataColumn::type to format.

Added GridView::dataColumnClass.
parent d1ebf655
......@@ -26,6 +26,7 @@ class GridView extends ListViewBase
const FILTER_POS_FOOTER = 'footer';
const FILTER_POS_BODY = 'body';
public $dataColumnClass = 'yii\widgets\grid\DataColumn';
public $caption;
public $captionOptions = array();
public $tableOptions = array('class' => 'table table-striped table-bordered');
......@@ -277,7 +278,7 @@ class GridView extends ListViewBase
$column = $this->createDataColumn($column);
} else {
$column = Yii::createObject(array_merge(array(
'class' => DataColumn::className(),
'class' => $this->dataColumnClass,
'grid' => $this,
), $column));
}
......@@ -300,14 +301,15 @@ class GridView extends ListViewBase
*/
protected function createDataColumn($text)
{
if (!preg_match('/^(\w+)(\s*:\s*(\w+))?$/', $text, $matches)) {
throw new InvalidConfigException('The column must be specified in the format of "Attribute" or "Attribute:Type"');
if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $text, $matches)) {
throw new InvalidConfigException('The column must be specified in the format of "Attribute", "Attribute:Format" or "Attribute:Format:Header');
}
return Yii::createObject(array(
'class' => DataColumn::className(),
'class' => $this->dataColumnClass,
'grid' => $this,
'attribute' => $matches[1],
'type' => isset($matches[3]) ? $matches[3] : 'text',
'format' => isset($matches[3]) ? $matches[3] : 'text',
'header' => isset($matches[5]) ? $matches[5] : null,
));
}
......
......@@ -22,7 +22,7 @@ class DataColumn extends Column
{
public $attribute;
public $value;
public $type;
public $format;
/**
* @var boolean whether to allow sorting by this column. If true and [[attribute]] is found in
* the sort definition of [[GridView::dataProvider]], then the header cell of this column
......@@ -90,6 +90,6 @@ class DataColumn extends Column
} else {
return parent::renderDataCellContent($item, $index);
}
return $this->grid->formatter->format($value, $this->type);
return $this->grid->formatter->format($value, $this->format);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment