Yii Framework Forum: Footer Na Cgridview - Yii Framework Forum

Jump to content

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

Footer Na Cgridview Rate Topic: -----

#1 User is offline   Jjunior 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 07-November 12

Posted 05 March 2013 - 02:58 PM

Estou tentando habilitar um footer em uma CGridView

Quero somar a coluna Total dos itens, mas não estou conseguindo passar o valor para que a sql busque os dados



       $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'itenssysos-grid',
	'dataProvider'=>$dataProvider,
	'columns'=>array(
		'id',
                'idsysos',
		'servicospecas',
		'qtde',
		'prunitario',
		'total',
		array(
			'class'=>'CButtonColumn',
                        'template'=>'{delete}',
                        'buttons'=>array(
                               'delete' => array
                                            (
                                            'url'=>'Yii::app()->createUrl("Sysos/DeleteItem", array("itenssysos"=>$data->id,"sysos"=>$data->idsysos))',
                                            ),
                        ),
		),
               array(
                    'name'=>'total',
                    'footer'=>$dataProvider->itemCount===0 ? '' : $this->loadSoma($model->id),
                    ),
	),
        )); 









       public function loadSoma($id)
	{
		$soma = Itenssysos::model()->findBySql('SELECT sum(total) FROM itenssysos WHERE idsysos=:id', array(':id'=>$id,));
            
//            	if($soma===null)
//			throw new CHttpException(404,'The requested page does not exist.');
		return $soma;
            
            return 'Total: R$'.$soma;
	}

0

#2 User is offline   Newerton 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 820
  • Joined: 27-April 10
  • Location:Campo Grande/MS - Cambé/PR, Brasil

Posted 05 March 2013 - 07:46 PM

Jjunior,

Qual o erro que retorna na sua função loadSoma()?

Tenta assim:
public function loadSoma($id) {
	$soma = Itenssysos::model()->findBySql('SELECT sum(total) as total FROM itenssysos WHERE idsysos=:id', array(':id'=>$id,));
            
	return 'Total: R$'.$soma->total;
}


Se de erro dizendo que o Itenssysos.total não está definido, e só declarar a váriavel no seu Model Itenssysos.

class Itenssysos extends CActiveRecord {

public $total;

[...]
}

Newerton Vargas de Araújo
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