O'Reilly logo

Yii2 By Example by Fabrizio Caldarelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required