Yii Framework Forum: [ASK]CGridView Totalin Data - Yii Framework Forum

Jump to content

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

[ASK]CGridView Totalin Data Rate Topic: -----

#1 User is offline   kfahmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 19-March 12

Posted 07 May 2012 - 02:45 AM

Bro teman kawan,,

ane ada class


<?php
 
class TotalColumn extends CGridColumn {
 
    private $_total = 0;
 
    public function renderDataCellContent($row, $data)
{
 
        $this->_total += $data->total;
 
        echo 'Rp. '.$this->_total;
    }
}
?>



tapi kalo paging nya tiap halaman totalnya berubah2.

misalnya ada 20 record di database,

terus jadi dua halaman di cgridview,

halaman pertama kolom totalnya nilainya record 1 ditambah sampai record 10,,

dihalaman kedua record 11 ditambah sampe halaman ke 20

yang saya mau kolom total ini langsung total record 1-20 bukan perhalaman / pagination. ada yang bisa atau tau gak ya?

solusi sementara ane jadi ga pake pagination di halaman ini supaya totalnya akurat. kalo pake pagination malah jadi cuma ada total per page aja :(
0

#2 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 07 May 2012 - 04:55 AM

klo aq bikin query lagi buat ngitung total. terus simpen di bawah Grid

[grid]
-[data1]-[data2]-[data3]
[endGrid]

echo "total"

gitu lah kira2.. :)
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#3 User is offline   kfahmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 19-March 12

Posted 08 May 2012 - 01:33 AM

View Postputrilangit, on 07 May 2012 - 04:55 AM, said:

klo aq bikin query lagi buat ngitung total. terus simpen di bawah Grid

[grid]
-[data1]-[data2]-[data3]
[endGrid]

echo "total"

gitu lah kira2.. :)



ada contoh code yang uda dipake blm kak? :D
0

#4 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 08 May 2012 - 01:39 AM

View Postkfahmi, on 08 May 2012 - 01:33 AM, said:

ada contoh code yang uda dipake blm kak? :D

contoh code... hmmm paling gini aja sih.. ^_^

foreach ($data as row) { // asumsi $data merupakan array yang sesuai dengan yang di grid.
$total = $total + $row->namaField;
}
echo $total


kali aja master yang di bawah saya tau... B)
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#5 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 08 May 2012 - 01:42 AM

atau mungkin kyk gini

foreach ($data as row) { // asumsi $data merupakan array yang sesuai dengan yang di grid.
$total[] = $row->namaField;
}
echo array_sum($total)

Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#6 User is offline   kfahmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 19-March 12

Posted 08 May 2012 - 03:02 AM

View Postputrilangit, on 08 May 2012 - 01:42 AM, said:

atau mungkin kyk gini

foreach ($data as row) { // asumsi $data merupakan array yang sesuai dengan yang di grid.
$total[] = $row->namaField;
}
echo array_sum($total)




hehehe makasih ya,

tp blm bisyaaa hehehe nungguin ada orang baik nih hehehe
0

#7 User is offline   angela88 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 144
  • Joined: 14-October 11
  • Location:Jakarta

Posted 08 May 2012 - 04:36 AM

kalo totalnya dikueri aja gimana???
langsung sum dari databasenya...
ga tau efektif ato ga nya c... :)
0

#8 User is offline   kfahmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 19-March 12

Posted 08 May 2012 - 11:18 PM

View PostAngela Ari, on 08 May 2012 - 04:36 AM, said:

kalo totalnya dikueri aja gimana???
langsung sum dari databasenya...
ga tau efektif ato ga nya c... :)


tapi gue malah butuhnya tiap gue search data di admin.php itu muncul kan recordnya. nah yang gue butuh total di view nya ri, dan ga masuk database hehehe
0

#9 User is offline   angela88 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 144
  • Joined: 14-October 11
  • Location:Jakarta

Posted 09 May 2012 - 01:44 AM

View Postkfahmi, on 08 May 2012 - 11:18 PM, said:

tapi gue malah butuhnya tiap gue search data di admin.php itu muncul kan recordnya. nah yang gue butuh total di view nya ri, dan ga masuk database hehehe

maksudnya pas di search itu totalnya juga dikueri...
misal :
$criteria->select ='--.*, sum(total) as grandtotal';


trus di viewnya
array(
			'name'=>'total',
			'footer'=>'$data->grandtotal',
		),


tapi yg jelas q lom pernah pake c...
jd ga tau jg...
hehehhehhe.... :P
0

#10 User is offline   kfahmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 19-March 12

Posted 09 May 2012 - 02:18 AM

View PostAngela Ari, on 09 May 2012 - 01:44 AM, said:

maksudnya pas di search itu totalnya juga dikueri...
misal :
$criteria->select ='--.*, sum(total) as grandtotal';


trus di viewnya
array(
			'name'=>'total',
			'footer'=>'$data->grandtotal',
		),


tapi yg jelas q lom pernah pake c...
jd ga tau jg...
hehehhehhe.... :P


error hehehe

muncul tulisam

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*, sum(total) as grandtotal FROM `tbl_reim` `t` WHERE id_emp='25' LIMIT 21474836' at line 1. The SQL statement executed was: SELECT --.*, sum(total) as grandtotal FROM `tbl_reim` `t` WHERE id_emp=:ycp0 LIMIT 2147483647

kalo diubah jadi gini

$criteria->select ='*, sum(total) as grandtotal';


datanya cuma 1 hehehehe gak ke select smua
0

#11 User is offline   angela88 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 144
  • Joined: 14-October 11
  • Location:Jakarta

Posted 10 May 2012 - 04:23 AM

hahahhaha.....
iya q lupa kalo pake sum data yg muncul cuma 1....
0

#12 User is offline   kokoadi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 03-December 08

Posted 10 May 2012 - 09:44 AM

http://www.yiiframew...in-a-cgridview/
0

#13 User is offline   ahmadroni 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 250
  • Joined: 14-June 09
  • Location:Yogyakarta-Indonesia

Posted 24 May 2012 - 12:29 AM

mantap nih gan... Ane nambah ilmu juga.. thank share linknya
Hospital Cost Management System and
Hospital Management Information System
0

#14 User is offline   rakimunroy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 08-June 12
  • Location:jakarta

Posted 20 June 2012 - 04:35 AM

saya masih newby nich di YII ,mohon bantuan untuk model
0

#15 User is offline   y_i_i 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 26-March 12

Posted 20 June 2012 - 10:38 AM

tapi ini agak bingung siih sesuai maksud atau engk..

data tetep diambil dr db kn trus ditampilin di grid view nyah ??

gini bukan ?? tapi agak ribet niih cos jd 3x tulis ulang sql,, pertama buat sum total, kedua buat paging, trus buat data nyah dehh,,
$sum=Yii::app()->db->createCommand
("SELECT sum(amount) as total FROM tbl_ ") ->queryScalar( );
//bisa langsung di echo disini
// echo "TOTAL : $sum";
$count=Yii::app()->db->createCommand
("SELECT count(amount) FROM tbl_ ") ->queryScalar( );
$sql=" SELECT date, nama, amount FROM tbl_ ";
$dataProvider=new CSqlDataProvider ($sql, array(
        'totalItemCount'=>$count,
        'sort'=>array(
                                'attributes'=>array(
                                          'date',
                        ),
                        ),
                        'db'=>Yii::app()->db,
                        'pagination'=>array(
                                'pageSize'=>30,
                        ),
                ));
$this->widget('zii.widgets.grid.CGridView', array(
                                'dataProvider'=>$dataProvider,//->getData(),
                                'columns'=>array(
)));



kaga tw kaya gini bukan yg dimaksud,, maaf klo salah,,
klo bener kaya gini maksud nyah yh kurang lebihlah yh,, agak gak hemat juga siihh,, mungkin ada saran lain hehehehhh
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