deez
deez

Reputation: 146

Yii Booster TbTotalSumColumn formatted as currency

I am using Yii Booster, and one of the widgets is TbTotalSumColumn.

When it renders the total in the footer, it uses the following code:

echo $this->totalValue? $this->evaluateExpression($this->totalValue, array('total'=>$this->total)) : $this->grid->getFormatter()->format($this->total, $this->type);

I have used CFormatter and created a 'currency' type, I have applied the formatting directly in the 'value' attribute, I have gone into the widget and applied the currency formatter there. It seems no matter what I do, I can only get either the values in the column to be formatted as currency, or the footer, never both.

Any help would be greatly appreciated.

Upvotes: 0

Views: 786

Answers (1)

Greg Fennell
Greg Fennell

Reputation: 176

I created a new class file in the components folder called TbTotalColumnCurrency.php. Then I call TbTotalSumColumnCurrency in my TbExtendedGridView code.

Yii::import('bootstrap.widgets.TbTotalSumColumn');

class TbTotalSumColumnCurrency extends TbTotalSumColumn
{
    protected function renderFooterCellContent()
    {
        if(is_null($this->total))
            return parent::renderFooterCellContent();

        echo $this->totalValue? $this->evaluateExpression($this->totalValue, array('total'=>number_format($this->total), 2, '.', '')) : $this->grid->getFormatter()->format(number_format($this->total, 2, '.', ''), $this->type);
    }
}

Hope this helps

array(
    'name'=>'Total',
    'type'=>'text',
    'value'=>'number_format($data->price*$data->quantity, 2, \'.\', \'\')',
    'class'=>'TbTotalSumColumnCurrency'
),

Upvotes: 3

Related Questions