From 1398de3f4ad25fd6fb41998f48fe9f4acb729472 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 2 Aug 2013 15:17:37 -0400 Subject: [PATCH] Renamed DataColumn::type to format. Added GridView::dataColumnClass. --- framework/yii/widgets/GridView.php | 12 +++++++----- framework/yii/widgets/grid/DataColumn.php | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/framework/yii/widgets/GridView.php b/framework/yii/widgets/GridView.php index 98b4884..85b90ea 100644 --- a/framework/yii/widgets/GridView.php +++ b/framework/yii/widgets/GridView.php @@ -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, )); } diff --git a/framework/yii/widgets/grid/DataColumn.php b/framework/yii/widgets/grid/DataColumn.php index 6035ed2..ebe6256 100644 --- a/framework/yii/widgets/grid/DataColumn.php +++ b/framework/yii/widgets/grid/DataColumn.php @@ -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); } }