如何使用C.Gridview - Yii格式化数字字符串 [英] How to format numeric string using C.Gridview - Yii

查看:158
本文介绍了如何使用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)'
    )
 ...

这篇关于如何使用C.Gridview - Yii格式化数字字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆