Using a grid
Now that we know how to get a data input source to pass to GridView, let's look at how to implement it. Minimal implementation of GridView requires two attributes for an array passed to a constructor: dataProvider
and columns
. The first parameter, dataProvider
, is the one we want to use in order to manipulate the data.
The second parameter, columns
, represents the columns of the table to be displayed, for example:
<?= \yii\grid\GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ 'id', 'floor', 'room_number', 'available_from:datetime', 'price_per_day:currency', ], ]) ?>
This code will display a table with data from $dataProvider
and five columns: id
, floor
, room_number
, available_from
, and price_per_day
; the last two columns are formatted firstly using datetime
and secondly using currency
. Colons are used to specify the formatter to be applied to the column data.
Note
The aspect of the table can be customized with...