Custom columns in a grid

As mentioned in the previous paragraph, the columns property of the GridView widget is mainly filled with strings.

When we need to apply a specific format, such as currency or date/time, we can append this specification to the column name with a colon and the type used for formatting, as currency or datetime.

But the most general form of a GridView column is an object of the yii\grid\Column class, derived by the yii\grid\DataColumn class.

A GridView column extended by the yii\grid\Column class is rendered using an array with the following keys:

 [ // can be omitted, as it is the default 'class' => 'yii\grid\DataColumn', 'attribute', // name of model attribute 'format', // format use to display data 'header', // header of column ...

Get Yii2 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.