Skip to content

Commit

Permalink
Added information about filters and header of DataColumn (yiisoft#14981
Browse files Browse the repository at this point in the history
…) [skip ci]
  • Loading branch information
githubjeka authored and samdark committed Dec 19, 2017
1 parent cb765ab commit f6b2d4d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/guide-ru/output-data-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ echo GridView::widget([
'attribute' => 'birthday',
'format' => ['date', 'php:Y-m-d']
],
'created_at:datetime', // короткий вид записи формата
[
'label' => 'Education',
'attribute' => 'education',
'filter' => ['0' => 'Elementary', '1' => 'Secondary', '2' => 'Higher'],
'filterInputOptions' => ['prompt' => 'All educations', 'class' => 'form-control', 'id' => null]
],
],
]);
```
Expand All @@ -235,6 +242,13 @@ echo GridView::widget([

Для конфигурации колонок данных также доступен короткий вид записи, который описан в API документации для [[yii\grid\GridView::columns|колонок]].

Используйте [[yii\grid\DataColumn::filter|filter]] и [[yii\grid\DataColumn::filterInputOptions|filterInputOptions]] для
настройки HTML кода фильтра.

По умолчанию заголовки колонок генерируются используя [[yii\data\Sort::link]]. Это можно изменить через свойство
[[yii\grid\Column::header]]. Для изменения заголовка нужно задать [[yii\grid\DataColumn::$label]], как в
примере выше. По умолчанию текст будет взят из модели данных. Подробное описание ищите в [[yii\grid\DataColumn::getHeaderCellLabel]].

#### ActionColumn

[[yii\grid\ActionColumn|ActionColumn]] отображает кнопки действия, такие как изменение или удаление для каждой строки.
Expand Down
13 changes: 13 additions & 0 deletions docs/guide/output-data-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ echo GridView::widget([
'attribute' => 'birthday',
'format' => ['date', 'php:Y-m-d']
],
'created_at:datetime', // shortcut format
[
'label' => 'Education',
'attribute' => 'education',
'filter' => ['0' => 'Elementary', '1' => 'Secondary', '2' => 'Higher'],
'filterInputOptions' => ['prompt' => 'All educations', 'class' => 'form-control', 'id' => null]
],
],
]);
```
Expand All @@ -256,6 +263,12 @@ For a list of available formatters see the [section about Data Formatting](outpu
For configuring data columns there is also a shortcut format which is described in the
API documentation for [[yii\grid\GridView::columns|columns]].
Use [[yii\grid\DataColumn::filter|filter]] and [[yii\grid\DataColumn::filterInputOptions|filterInputOptions]] to
control HTML for the filter input.
By default, column headers are rendered by [[yii\data\Sort::link]]. It could be adjusted using [[yii\grid\Column::header]].
To change header text you should set [[yii\grid\DataColumn::$label]] like in the example above.
By default the label will be populated from data model. For more details see [[yii\grid\DataColumn::getHeaderCellLabel]].
#### Action column <span id="action-column"></span>
Expand Down
8 changes: 7 additions & 1 deletion framework/grid/DataColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class DataColumn extends Column
* @var string|array|null|false the HTML code representing a filter input (e.g. a text field, a dropdown list)
* that is used for this data column. This property is effective only when [[GridView::filterModel]] is set.
*
* - If this property is not set, a text field will be generated as the filter input;
* - If this property is not set, a text field will be generated as the filter input with attributes defined
* with [[filterInputOptions]]. See [[\yii\helpers\BaseHtml::activeInput]] for details on how an active
* input tag is generated.
* - If this property is an array, a dropdown list will be generated that uses this property value as
* the list options.
* - If you don't want a filter for this data column, set this value to be false.
Expand All @@ -108,6 +110,10 @@ class DataColumn extends Column
* @var array the HTML attributes for the filter input fields. This property is used in combination with
* the [[filter]] property. When [[filter]] is not set or is an array, this property will be used to
* render the HTML attributes for the generated filter input fields.
*
* Empty `id` in the default value ensures that id would not be obtained from the model attribute thus
* providing better performance.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $filterInputOptions = ['class' => 'form-control', 'id' => null];
Expand Down

0 comments on commit f6b2d4d

Please sign in to comment.