Add Dynamic Value CGridView Footer

i have added a custom column in CGridView named Balance and calculate current balance by using this now i want to add current balance in footer like below :

i m using code :


class BalanceColumn extends CGridColumn {

		 

		    private  $_total = 0;

		   	

		   public function renderDataCellContent($row, $data) { // $row number is ignored

		  		

		    	$_minus = array('Returned','Expense');

		    	

		    	if(in_array($data->idIncomeType0->Name, $_minus) || in_array($data->idIncomeType0->Category, $_minus))

		    	$this->_total-=$data->Amount;

		    	else

		    	$this->_total += $data->Amount;

		 		

		        echo $this->_total;

		        

		    }

		     public  function renderFooterCellContent(){

		     	   

		     	echo '28';

		     }

		   

			

		  

		}

		

?>





<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'payments-grid',

	'dataProvider'=>$cdataProvider,

	

	'columns'=>array(

	.....,

        array(

            'header' => 'Balance',

            'class'  => 'BalanceColumn',

            'footer' => '',

            

        ),

	  

	.....	),

	

)); 

Right now i just echo the value , how could i get the last balance from renderDataCellContent? m i following the right way ? :(

no one intrested :unsure: :(

why dont you

…,

    array(


        'header' =&gt; 'Balance',


        'class'  =&gt; 'BalanceColumn',


        'footer' =&gt; &#036;model-&gt;getBalance(),


        ...........

i.e make a function in your model ($model->getBalance()) or controller (using $this->getBalance())

The Zohan is right, if you calculate the balance in this way, it won’t work if you have more page, you will get only the balance for the first page.

Create a function in the model for get the balance of all records and dispay as suggested the Zohan