Yii Framework Forum: sum total in footer - Yii Framework Forum

Jump to content

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

sum total in footer Rate Topic: -----

#1 User is offline   mgs3bg 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 12-May 11

Posted 16 May 2011 - 05:38 AM

Привет на всички?
от скоро разглеждам yii, но не мога да намеря лесен начин да си направя view, което да показва сумата на дадена колона отдолу.
Намерих начин:
в контролера:
public function search2()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id',$this->id);
$criteria->compare('kod',$this->kod,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('matrix',$this->matrix,true);
$criteria->compare('teglo',$this->teglo);
$criteria->compare('grupa',$this->grupa,true);
$criteria->select = 'kod,name,sum(teglo) as teglo';

$criteria->group = 'kod';


return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}




public function totals()
{
$criteria=new CDbCriteria;
$criteria->select='SUM(teglo) as teglo';
return $this->commandBuilder->createFindCommand($this->getTableSchema(),$criteria)->queryScalar();
}
във view:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'opisdetailsall-grid',
'dataProvider'=>$model->search2(),
'filter'=>$model,
'columns'=>array(

'kod',
'name',

array(
name=>'teglo',
footer=>$model->totals(),

),

),
));
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