How to format numeric string using C.Gridview - Yii

旧城冷巷雨未停 提交于 2019-12-25 02:26:18

问题


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!


回答1:


try

'columns' => array(
    array(
        'name' => 'totaldue',
        'value' => 'number_format($data->totaldue)'
    )
 ...


来源:https://stackoverflow.com/questions/24936831/how-to-format-numeric-string-using-c-gridview-yii

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!