Cgridview Get Summery Of Checked Row Values

Hi all,

I am using cgridview with ccheckboxcolumn to select the invoices for processing. I want to display the total amount of checked invoices before they processed. Can any one help me to do this ?

So far I tried with this post but failed because ccheckboxcolumn not support to the event ‘onChange’ !

hi,anilherath .u can use checkBoxList ,event ‘onClick’ can help .

Dear Life_free,

Thank you for the quick response. I tried as you proposed but failed ( I have less experience in Yii).

Actually What I did so far is create the cgridview with ‘CCheckBoxColumn’;




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

    'id' => 'banking-grid',

    'selectableRows' => 2, // multiple rows can be selected

    'dataProvider' => $model->searchUpdate(),

    'filter' => $model,

    'columns' => array(

        array(

            'class' => 'CCheckBoxColumn',

        

            'value'=> '$data->id',

            

         

        ),

        array(

            'name' => 'banking',

            'value' => '($data->banking == 1) ? Yii::t(\'app\', \'Yes\') : Yii::t(\'app\', \'No\')',

            'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),

        ),

        'date',

        array(

            'name'=>'customer_id',

            'value'=>'$data->customer->name',

            'filter' => GxHtml::listDataEx(Customer::model()->findAllAttributes(null, true)),

        ),

        'amount',

      ),

));



I want to display the Total ‘amount’ of checked rows before submit.

Dear AnilHerath

Kindly check whether the following is helpful to you.

I presume that you need the total of all values in a column in checked rows.

Register the following script in admin.php

Also create a textField to collect the total value.

Model:Test

id of CGridView:test-grid

checkbox column is the 6th column in my grid.

I want to calculate the the total values of 3rd column.




<?php

Yii::app()->clientScript->registerScript('total','

$("body").on("change","#test-grid input[type=\"checkbox\"]",function(){

var checked=$("#test-grid input[name=\"test-grid_c5[]\"]:checked");

var value=0;

$.each(checked,function(i,j){

	

	var row=$(j).parent().siblings();

	value+=parseFloat($(row[2]).html());

	});

$("#total").val(value);

return false;

})





');


echo CHtml::textField('Total','',array('id'=>'total','placeholder'=>'Get the total'));



Note:




var checked=$("#test-grid input[name=\"test-grid_c5[]\"]:checked");



Here number 5 indicates checkbox is in 6th column of the grid.




value+=parseFloat($(row[2]).html());



Here number 2 indicates that we are calculating the values in the 3rd column.

Regards.

Dear Seenivasan,

You ended my problem troubled during last two days. Thank you very much. Thank you very much for your solution and the great way of explanation.