Changing The Default Message For A Null Value In The Gridview Widget

I’m looking to change the default message for null values while using the GridView widget. Currently it defaults to ‘Not Set’. I would like to change this to another message depending on what the field is. Any ideas on how to go about this?

On Yii 1.1.14, you can change it by extending the CGridView and overriding the public variable $nullDisplay. ( https://github.com/yiisoft/yii/blob/1.1.14/framework/zii/widgets/grid/CGridView.php#L257 )

[size="2"]Step by step:[/size]

create a new file MyGridView.php [size="2"]and put it on the extensions folder( or anything you want. )[/size]


class MyGridView extends CGridView

{

    public $nullDisplay = "something you want here...";

    // ... some codes here if you like.

}

[font="Consolas, Liberation Mono, Menlo, Courier, monospace"][color="#333333"]Then on the implementation:[/color][/font]

[font="Consolas, Liberation Mono, Menlo, Courier, monospace"] [/font]


$this->widget('ext.MyGridView', array(

 	// properties here...

 ));

Thanks! Extending widgets seems to be done a little differently in Yii 2.0 than in 1.x. I haven’t quite got it working, but that’s definitely the way to do it.

The Yii2 GridView has an emptyCell property.

However, I think the value (not set) comes from the Yii::$app->formatter->nullDisplay.

You can set nullDisplay to a value you need in your Yii Formatter settings in config.