Error Displaying Boolean In Cgridview

Hello!

I have two fields in a model that are Boolean datatype.

Strangely enough, CGridView displayed always as ‘Yes’, that is, as ‘true’ (it was autogenerated with Giix).

In my favour, saying that CDetailView shows the correct output: ‘Yes’ or ‘No’ depending on the numerical values ​​respectively ‘1’ or ‘0’ (true, false).

In my case, I use MySql database. The Booleans in MySql are built with TINYINT (1) and, in fact, Yii recognize correctly these, as Booleans, but not CGridView.

My question is: Is normal? Do I need to do some change?

Thanks in advance.

According to the documentation for the column property of Cgridview:

When a column is specified as a string, it should be in the format of "name:type:header", where "type" and "header" are optional. A CDataColumn instance will be created in this case, whose CDataColumn::name, CDataColumn::type and CDataColumn::header properties will be initialized accordingly.

The default for the type property is Text. Try specifying the type as "boolean".

Amazing @richmest!

Hopefully, Giix auto-formats the CGridView columns, but get complicated much… and fails.

[size="2"]




<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id' => 'language-grid',

	'dataProvider' => $model->search(),

	'filter' => $model,

	'columns' => array(

		'code',

		'name',

		array(

					'name' => 'active',

					'value' => '($data->active === 0) ? Yii::t(\'app\', \'No\') : Yii::t(\'app\', \'Yes\')',

					'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),

					),

		...

[size="2"]… when simply must by define the column as boolean type (how well said @ richmest).[/size]

How? Enough with specify the name of the column thus: ‘name_column: boolean’, such as showed the following code.[/size]

[size="2"]




<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id' => 'language-grid',

	'dataProvider' => $model->search(),

	'filter' => $model,

	'columns' => array(

		'code',

		'name',

                'active:boolean',

I hope, it is usefull to others.[/size]