2015-12-17 30 views
0

十進制格式我有這樣的代碼:
解決:在Yii中TBGridview

<?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}' 
     ), 
    ), 
)); 
?> 

結果只有整數和搜索篩選器的工作,如何將它轉變成十進制格式,但搜索篩選器還工作嗎?
我試圖把它變成:

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

但它使搜索過濾器工作不正常。

回答

0
Try This:- 
    $this->widget('zii.widgets.grid.CGridView', array(
     'dataProvider' => $dataProvider, 
     'columns'  => array(
      'cost',   // display the 'cost' attribute 
      array(   // display the 'cost_in_dollars' using an expression 
       'name' => 'cost_in_dollars', 
       'value' => 'number_format($data->cost/100, 2)', 
      ), 
     ), 
    )); 
相關問題