How to format numeric string using C.Gridview - Yi

2019-08-17 19:50发布

I've recently run into the issue where I have a string of numbers (totaldue) that I would like to format in my C.Gridview so that 10000 would become 10,000

So far I have done this

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'paylist-grid',
'dataProvider'=>$dataProvider,
'filter'=>$model,
'columns'=>array(

    'totaldue'=> array(
        'value'=>'totaldue',         
        'type'=>'number'),
// more code ... 

This would work if total due was a int or double, but because it is a string, I am getting thrown an error.

I attempted to change number into an int by using intval ex.

'totaldue'=> array(
        'value'=>intval('totaldue'),          
        'type'=>'number'),
// more code ... 

but this threw back the error call_user_func_array() expects parameter 1 to be a valid callback, no array or string given. I know that this can be done - but I'm struggling to implement it. Any advice/help would be greatly appreciated!

标签: php gridview yii
1条回答
一纸荒年 Trace。
2楼-- · 2019-08-17 20:24

try

'columns' => array(
    array(
        'name' => 'totaldue',
        'value' => 'number_format($data->totaldue)'
    )
 ...
查看更多
登录 后发表回答