Yii Framework Forum: How To Show $ (Dollar) Character In Cgridview Column Value - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Show $ (Dollar) Character In Cgridview Column Value Rate Topic: -----

#1 User is offline   Ravi Verma 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 14-May 12

Posted 19 November 2012 - 07:44 AM

Hi Guys - I am having below column in CGridView widget:


array(
  'name'=>'cost',
  'header'=>'Cost',
  'value'=>'Yii::app()->params["currencyFormat"].isset($data->defaultVendor["0"]->purchase_price)?$data->defaultVendor["0"]->purchase_price:null'
),


since, value is being calculated, I need to show "Dollar Sign" in front of it's value. HOw I can append it?

No doubt, I can append string functions like substr or chr etc. But those are also not working, I have tried below statement also:


array('name'=>'cost',
 'header'=>'Cost',
 'value'=>'chr(36).Yii::app()->params["currencyFormat"].isset($data->defaultVendor["0"]->purchase_price)?$data->defaultVendor["0"]->purchase_price:null'
),


Thanks,
0

#2 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,332
  • Joined: 21-February 11
  • Location:Greece

Posted 19 November 2012 - 07:51 AM

add 'type' => 'raw' in column array
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,670
  • Joined: 04-March 10
  • Location:UK

Posted 19 November 2012 - 07:59 AM

You might do better putting this logic into an anonymous function.

array('name'=>'cost',
    'header'=>'Cost',
    'value'=>function($data){
        $purchasePrice = isset($data->defaultVendor["0"]->purchase_price)
                       ? $data->defaultVendor["0"]->purchase_price
                       : null;
        return '$' . Yii::app()->params["currencyFormat"] . $purchasePrice;
    },
),


It would at least make the logic clearer, which might prevent problems when determining how to add the symbol.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users