I have gridview using TbExtendedGridView yii booster, in footer gridview i want show the sum of field using extendedSummary, i have follow the tutorial in yiibooster web but i can't show the extendedSummary to show the sum of column. Pls help me what's wrong in my code below ?. in the footer just show the box with blank text.
//this isi my gridview code
$no_loan= $_GET[no_loan];
$sql2="SELECT * from tbangsuran where nomor_pinjaman = '$no_loan' and status_bayar=1 order by no ASC";
$sqlProvider = new CSqlDataProvider($sql2);
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
//'filter'=>$model,
'id'=>'tbangsuran-grid',
'type'=>'striped bordered',
'template' => "{items}\n{extendedSummary}",
'dataProvider' =>$sqlProvider,
'columns'=>array(
array(
'name'=>'Angsuran Ke',
'headerHtmlOptions'=>array('style'=>'text-align:center; width:90px;'),
'htmlOptions'=>array('style'=>'text-align:center'
),
'value'=> '$data[\'no\']',
),
array(
'name'=>'Tanggal Tagihan',
'headerHtmlOptions'=>array('style'=>'text-align:center;width:90px;'),
'htmlOptions'=>array('style'=>'text-align:center'),
'value'=> 'date("d-m-Y",strtotime($data[\'tanggal_bayar\']))',
),
//'nomor_pinjaman',
array(
'name'=>'Tunggakan Pokok',
'headerHtmlOptions'=>array('style'=>'text-align:center; width:120px;'),
'htmlOptions'=>array('style'=>'text-align:right'),
'value'=> 'number_format($data[\'pastdue_pokok\'],0,"",".")',
),
array(
'name'=>'Tunggakan Bunga',
'headerHtmlOptions'=>array('style'=>'text-align:center; width:120px;'),
'htmlOptions'=>array('style'=>'text-align:right'),
'value'=> 'number_format($data[\'pastdue_bunga\'],0,"",".")',
),
array(
'name'=>'Total Tunggakan',
'headerHtmlOptions'=>array('style'=>'text-align:center;width:120px;'),
'htmlOptions'=>array('style'=>'text-align:right'),
'value'=> 'number_format($data[\'pastdue_pokok\']+$data[\'pastdue_bunga\'],0,"",".")',
),
),
'extendedSummary' => array(
'title' => 'Total Tunggakan',
'columns' => array(
'pastdue_pokok' => array('label'=>'Total Tunggakan','class'=>'TbSumOperation')
)
),
'extendedSummaryOptions' => array(
'class' => 'well pull-right',
'style' => 'width:300px'
),
));
You must use the same column name in extendedSummary field.
In your case would be:
'extendedSummary' => array(
'title' => 'Total Tunggakan',
'columns' => array(
'Total Tunggakan' => array('label'=>'Total Tunggakan','class'=>'TbSumOperation')
)
),
I recommend you to use short column name to this tasks.
Hope this helps!
Related
I am new to cakephp and I want to add or, and, and like to my existing query.
I want to make a condition like this
WHERE 'Message.user_id = Contact.user_id' AND 'Message.mobileNo LIKE'=>"%Contact.mobileNo" OR LIKE'=>"%Contact.homeNo" OR LIKE'=>"%Contact.workNo"
My query is
$this->bindModel(array(
'belongsTo' => array(
'Contact' => array(
'className' => 'Contact',
'foreignKey' => false,
'conditions' => array(
'Message.user_id = Contact.user_id',
'Message.mobileNo = Contact.mobileNo'
),
'type' => 'inner'
)
)
), false);
$this->find('all', array('conditions' => array(),
'fields' => array('DISTINCT mobileNo')));
you can use like below in your existing query.
$this->find('all', array(
'conditions' => array(
'OR' => array(
array(
"Message.mobileNo LIKE" => "%Contact.mobileNo",
),
array(
"Message.mobileNo LIKE" => "%Contact.homeNo",
),
array(
"Message.mobileNo LIKE" => "%Contact.workNo",
)
)
),
'fields' => array('DISTINCT mobileNo')
));
And you can also refer Detail Document for simple search with like
you can use: for "like"
$this->Post->find("all",array('condition'=>array('Author
LIKE'=>"ad%")));
above query will give You the data from table posts where author name starts with "ad".
for "OR"
$this->Post->find("all",array('condition'=>array("OR"=>array('Author
LIKE'=>"ad%",'Author LIKE'=>"bo%"))));
above query will give You the data from table posts where author name starts with "ad" OR "bo"
This blog post can b useful to u as well!
I have tried to implement the sorting using BootGridView but it does not seem to work. Here is the line of code.
<?php $this->widget('bootstrap.widgets.BootGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'user_id',
array('name'=>'user_type',
'value'=>'User::getType($data->user_type)'),
'username',
array('header'=>'Name',
'type'=>'raw',
'value'=> 'CHtml::link($data->firstname." ".$data->lastname, array("view", "id"=>$data->id))'
),
array('name' => 'status',
'type' => 'raw',
'value' => '$data->status == 1 ? "Active" : CHtml::link("In Active", "javascript:void(0);", array("id" => "active_" . $data->id, "onClick"=>"js:activate($data->id)"))'
),
/*
'email',
'dob',
'profession',
'hobby',
'height',
'weight',
'weight_taken_on',
'login_attempt',
'registration_date',
*/
array(
'class'=>'bootstrap.widgets.BootButtonColumn',
),
),
)); ?>
The code does not seem to sort the table as expected. What could be the possible problem in this. ?
Sorting is configured in the data provider, not in the grid view. So you should look into the search() method of your model. You need something like this:
return new CActiveDataProvider('User',array(
// ...
'sort' => array(
'attributes' => array(
'name',
'email',
// ...
Have a look at CSort and especially the attributes property there to learn more about sort options you can use here.
In YII I have:
$dataProvider = new CArrayDataProvider ($auctions ,
array(
'pagination'=>array(
'pageSize'=> 12,
),
));
$this->widget('zii.widgets.CListView', array(
'dataProvider'=> $dataProvider,
'itemView' => '_frontpageAuction',
'summaryText' => '',
'emptyText' => '
No auctions available to display.
',
));
How do I change it so the pager doesn't appear at the bottom of the grid, but rather at the top?
Use the template property of CListView:
$this->widget('zii.widgets.CListView', array(
'dataProvider'=> $dataProvider,
'itemView' => '_frontpageAuction',
'summaryText' => '',
'emptyText' => '
No auctions available to display.
',
'template'=>'{pager}{items}'
));
Also:
These tokens are recognized: {summary}, {sorter}, {items} and {pager}. They will be replaced with the summary text, the sort links, the data item list, and the pager.
A similar property is available for CGridView also: template.
I have the following model:
$values = $this->PtlUserdata->find('all', array(
'fields' => array(
'PtlUserdata.field',
'PtlUserdata.value',
'PtlUserdata.timestamp'
),
'conditions' => array(
'PtlUserdata.user_id' => $user->get('id'),
),
'order' => array('PtlUserdata.timestamp' => 'DESC'),
'group' => array('PtlUserdata.field')
));
I'm trying to order the results by timestamp and then group the results by field, so I can get the most recent record with that field name.
Does anybody know how to do this is cakephp?
Thanks in advance for any help, much appreciated :)
This is the default behavior for the database. You will have to come up with some sort of workaround to do it.
An idea: CakePHP: Group by ID and Order by date
Does this work:
$values = $this->PtlUserdata->find('all', array(
'fields' => array(
'PtlUserdata.field',
'PtlUserdata.value',
'max(PtlUserdata.timestamp)'
),
'conditions' => array(
'PtlUserdata.user_id' => $user->get('id'),
'PtlUserdata.timestamp' => 'max(PtlUserdata.timestamp)',
),
'group' => array(
'PtlUserdata.field',
'PtlUserdata.timestamp'
)
));
I haven't had the chance to test this but you definitely need to be grouping by PtlUserdata.timestamp.
I am tyring to display somedata in desending order in YII view.HOw Do I order the data by studentID desc by default ?
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'student-grid',
'criteria'=>array(
'order'=>'StudentID DESC',
),
'dataProvider' => Agent::getStudents($model->agent_id),
'columns' => array(
'StudentID',
'first_name',
'last_name',
'dob',
'gender',
array(
'header' => 'Options',
'class' => 'CButtonColumn',
'template'=>'{View}',
'buttons'=>array(
'View' => array(
'url'=> 'Yii::app()->createUrl("/students/view/" . $data->StudentID)',
),
),
),
),
)); ?>
Thanks Ab
In your dataProvider (i assume that's what getStudents() function returns) add another array to your config array :) Like:
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$some_criteria,
/* Your array */
'sort'=>array(
'defaultOrder'=>array(
'StudentID'=>true,
),
),
/***/
));
Value 'false' in 'defaultOrder' array refers to ascending order, 'true' refers to descending order.
I hope that's what you're looking for :).
Also check out this forum thread: http://www.yiiframework.com/forum/index.php/topic/8428-cgridview-default-sort/
and this doc: http://www.yiiframework.com/doc/api/1.1/CSort#defaultOrder-detail
Regards.