phpyiicgridview

Decimal Format in Yii TBGridview


I have code like this :

<?php 
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'appliances-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
        array(
            'name'=>'price',
            'type'=>'number',
            'htmlOptions'=>array('style' => 'text-align: right;'),
        ),
        array(
            'class'=>'bootstrap.widgets.TbButtonColumn',
            'template'=>'{update}{delete}'
        ),
    ),
)); 
?>

the result is integer number only and search filter is work, how to change it into decimal format but search filter still working ?
I tried to change it into :

array(
    'name'=>'price',
    'type'=>'number',
    'htmlOptions'=>array('style' => 'text-align: right;'),
    'value'=>function($data)
             {
                return number_format($data->price,2,',','.');
             },
),

But it makes search filter not working properly.


Solution

  • I found the answers here :

    1. Yii Number Formatting
    2. How to format numeric string using C.Gridview - Yii

    And also I found this link Yii , show different date format in cgridview