如何使用C.Gridview - Yii格式化数字字符串
我最近遇到了一个问题,那里有一串数字(totaldue),我想在我的C.Gridview中设置格式,这样10000会变成10,000。
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 ...
如果总计到期时间为int或者double,但是因为它是一个字符串,所以我得到了一个错误。
This would work if total due was a int or double, but because it is a string, I am getting thrown an error.
我试图用intval
ex。
I attempted to change number into an int by using intval ex.
'totaldue'=> array(
'value'=>intval('totaldue'),
'type'=>'number'),
// more code ...
但是这会抛出错误call_user_func_array()期望参数1是有效的回调,没有给出数组或字符串。我知道这可以做到 - 但我正在努力实现它。任何建议/帮助将不胜感激!
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!
尝试
try
'columns' => array(
array(
'name' => 'totaldue',
'value' => 'number_format($data->totaldue)'
)
...