data-widgets.md 1.15 KB
Newer Older
1
Data widgets
2 3
============

Carsten Brandt committed
4 5 6 7
GridView
--------

The [[yii\grid\GridView]] widget is a powerful tool to create a data grid that provides pagination, sorting
8
and filtering of the data out of the box. See the [data grid section](data-grid.md) for more details.
Carsten Brandt committed
9 10


11 12 13 14 15 16 17 18
ListView
--------



DetailView
----------

19
DetailView displays the detail of a single data [[yii\widgets\DetailView::$model|model]].
20 21
 
It is best used for displaying a model in a regular format (e.g. each model attribute is displayed as a row in a table).
22
The model can be either an instance of [[\yii\base\Model]] or an associative array.
23
 
24
DetailView uses the [[yii\widgets\DetailView::$attributes]] property to determines which model attributes should be displayed and how they
25 26 27 28 29 30
should be formatted.
 
A typical usage of DetailView is as follows:
 
```php
echo DetailView::widget([
31 32 33 34 35 36 37 38 39
    'model' => $model,
    'attributes' => [
        'title',             // title attribute (in plain text)
        'description:html',  // description attribute in HTML
        [                    // the owner name of the model
            'label' => 'Owner',
            'value' => $model->owner->name,
        ],
    ],
40 41
]);
```