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:
<?= yiigridGridView::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.
Columns in the grid table can be identified using strings, but in general they are configured in terms of yiigridColumn
classes.
18.189.180.76