Browse Source

Renamed DataColumn::type to format.

Added GridView::dataColumnClass.
tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
1398de3f4a
  1. 12
      framework/yii/widgets/GridView.php
  2. 4
      framework/yii/widgets/grid/DataColumn.php

12
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,
));
}

4
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);
}
}

Loading…
Cancel
Save