Override Formatter Default in GridView


(DBCreator) #1

In my config I have set the default Formatter setting, but I have an single column in my Index GridView that I would like to override the thousandSeparator to be ’ ’ instead of the default ‘,’, how can I achieve this?

This is my current view definition for the column in question

[
	'attribute'=>'Finish',
	'contentOptions' => ['class' => 'text-right'],
	'format'=>['decimal', 0],
],

(Johnson) #2

Hi there,

The syntax for format is right as per your code above.

You can refer the page

https://www.yiiframework.com/doc/api/2.0/yii-i18n-formatter#$decimalSeparator-detail

and some times based on your time zone you set the decimal separator may take effect!


(DBCreator) #3

Any chance you could give me a formal example on how I would implement it with my column code?


(Eloy Gonzalez) #4

Try with this code

[
    'attribute'=>'Finish',
    'contentOptions' => ['class' => 'text-right'],
    'format'=> 'decimal',
],

(DBCreator) #5

Gives me the same result, since it will rely on the default formatter properties from my config file.

I was hoping I could do something like

            [
                'attribute'=>'Finish',
                'contentOptions' => ['class' => 'text-right'],
                'formatter' => [
                    'thousandSeparator' => ' ',
                ],
                'format'=>['decimal', 0],
            ],

or

            [
                'attribute'=>'Finish',
                'contentOptions' => ['class' => 'text-right'],
                'format'=>['decimal', 0, [ 'thousandSeparator' => ' ']],
            ],

but of course neither of these works.

I figure it can be overridden using options, just can’t figure it out or find any online examples either.