yii cgridview expression evaluation does not work on pagination - yii

I have the following cgrid view which works and evalutes and displays the 1st 18 results as pagination is set to 18.
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'projects-grid',
'dataProvider'=>$model->search(false),
'filter'=>$model,
'rowCssClassExpression'=>'($data->PERCENT == 100)? "yellow" : ($row%2?"even":"odd")',
'columns'=>array(
array(
'name' => 'PROJID',
'htmlOptions' => array('style'=>'width:70px'),
),
array(
"header"=>"Client",
"value"=>' ($data->oRDERNO->ACCOUNTID == "")? "" : (isset($data->oRDERNO->aCCOUNTold->COMPANY))? $data->oRDERNO->aCCOUNTold->COMPANY: (isset($data->oRDERNO->aCCOUNTsugar->name)) ? $data->oRDERNO->aCCOUNTsugar->name : "" ',//'(strlen($data->oRDERNO->ACCOUNTID)>10) ? $data->oRDERNO->aCCOUNTsugar->name : ""',//(isset($data->oRDERNO->aCcounts0->COMPANY)) ? $data->oRDERNO->aCcounts0->COMPANY : "" '
),
array(
'name' => 'PROJECT',
'header'=>"Project",
'type' => 'raw',
'filter'=>$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'attribute'=>'PROJECT',
'model'=>$model,
'name'=>'Projects[PROJECT]',
'options'=>array(
'minLength'=>'2',
),
'htmlOptions'=>array(
'id' => 'Projects_PROJECT_search'
),
),true),
),
'country',
array(
'class'=>'CButtonColumn',
'template'=>'{update}{view}',
'htmlOptions' => array('style'=>'width:5px'),
//"style"=>"width:5px"
'buttons'=>array(
'update'=>array(
'visible'=>'(isset($data->oRDERNO->ACCOUNTID)) ? (strlen($data->oRDERNO->ACCOUNTID)>10) ? true :false: false',
),
/*'view'=>array(
'visible'=>'(isset($data->oRDERNO->ACCOUNTID)) ? (strlen($data->oRDERNO->ACCOUNTID)>10) ? true :false: false',
),*/
),
),
),
)); ?>
How ever when i try to got next it errors.
<h1>PHP Error [8]</h1>
<p>Trying to get property of non-object (/opt/yii-1.1.14.f0fee9/framework/base/CComponent.php(612) : eval()'d code:1)</p>
<pre>#0 /opt/yii-1.1.14.f0fee9/framework/base/CComponent.php(612) : eval()'d code(1): CWebApplication->handleError()
#1 /opt/yii-1.1.14.f0fee9/framework/base/CComponent.php(612): eval()
#2 /opt/yii-1.1.14.f0fee9/framework/zii/widgets/grid/CDataColumn.php(137): CDataColumn->evaluateExpression()
#3 /opt/yii-1.1.14.f0fee9/framework/zii/widgets/grid/CGridColumn.php(151): CDataColumn->renderDataCellContent()
#4 /opt/yii-1.1.14.f0fee9/framework/zii/widgets/grid/CGridView.php(616): CDataColumn->renderDataCell()
#5 /opt/yii-1.1.14.f0fee9/framework/zii/widgets/grid/CGridView.php(572): CGridView->renderTableRow()
#6 /opt/yii-1.1.14.f0fee9/framework/zii/widgets/grid/CGridView.php(482): CGridView->renderTableBody()
#7 /opt/yii-1.1.14.f0fee9/framework/zii/widgets/CBaseListView.php(167): CGridView->renderItems()
#8 unknown(0): CGridView->renderSection()
#9 /opt/yii-1.1.14.f0fee9/framework/zii/widgets/CBaseListView.php(150): preg_replace_callback()
#10 /opt/yii-1.1.14.f0fee9/framework/zii/widgets/CBaseListView.php(135): CGridView->renderContent()
#11 /opt/yii-1.1.14.f0fee9/framework/web/CBaseController.php(173): CGridView->run()
#12 /opt/paradox/protected/views/projects/entry.php(90): ProjectsController->widget()
#13 /opt/yii-1.1.14.f0fee9/framework/web/CBaseController.php(126): require()
#14 /opt/yii-1.1.14.f0fee9/framework/web/CBaseController.php(95): ProjectsController->renderInternal()
#15 /opt/yii-1.1.14.f0fee9/framework/web/CController.php(869): ProjectsController->renderFile()
#16 /opt/yii-1.1.14.f0fee9/framework/web/CController.php(782): ProjectsController->renderPartial()
#17 /opt/paradox/protected/controllers/ProjectsController.php(811): ProjectsController->render()
#18 /opt/yii-1.1.14.f0fee9/framework/web/actions/CInlineAction.php(49): ProjectsController->actionAdmin()
#19 /opt/yii-1.1.14.f0fee9/framework/web/CController.php(308): CInlineAction->runWithParams()
#20 /opt/yii-1.1.14.f0fee9/framework/web/CController.php(286): ProjectsController->runAction()
#21 /opt/yii-1.1.14.f0fee9/framework/web/CController.php(265): ProjectsController->runActionWithFilters()
#22 /opt/yii-1.1.14.f0fee9/framework/web/CWebApplication.php(282): ProjectsController->run()
#23 /opt/yii-1.1.14.f0fee9/framework/web/CWebApplication.php(141): CWebApplication->runController()
#24 /opt/yii-1.1.14.f0fee9/framework/base/CApplication.php(180): CWebApplication->processRequest()
#25 /opt/paradox/index.php(31): CWebApplication->run()
</pre>

Well, I believe on your second page you are missing things. 1 example might be that
$data->oRDERNO->ACCOUNTID is not existent. If there is no $data->oRDERNO then accessing $data->oRDERNO->ACCOUNTID would thrown an error exactly how you see it. try getting to the second page in the browser to see that this is the case.

Related

extendedSummary Yiiboster not show the sum total of gridview

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!

Passing ID to CGridView

How to pass grid row id from CGridView to filter values in another CGridView opened in Dialog
My View Code for Form Grid(see screenshot),
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'document-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'class' => 'CButtonColumn',
'template' => '{edit}{DocumentDelete}',
'buttons' => array(
'DocumentDelete' => array(
'imageUrl'=>Yii::app()->request->baseUrl.'/images/delete.png',
'url'=>'Yii::app()->createUrl("baseContact/DocumentDelete", array("id"=>$data->crm_document_id))',
),
'edit' => array(
'imageUrl'=>Yii::app()->request->baseUrl.'/images/update.png',
'url'=>'Yii::app()->createUrl("baseContact/edit", array("id"=>$data->crm_document_id))',
),
),),
'crm_document_id',
'name',
'doc_type',
'delivery_method',
'content_subject',
'content_body',
'is_active',
),
)); ?>
View Code for Popup Grid,
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'ManagedocumentAttach-grid',
'dataProvider'=>DocumentAttachmentModel::model()->search(),
//'filter'=>$model,
'columns'=>array(
array(
'name'=>'',
'value'=>'CHtml::checkBox("cid[]",null,array("value"=>$data->crm_document_attachment_id,"id"=>"cid_".$data->crm_document_attachment_id))',
'type'=>'raw',
'htmlOptions'=>array('width'=>5),
//'visible'=>false,
),
'crm_document_id',
'name',
'type',
),
)); ?>
how to pass Form edited row id to Popup GridView ?
Clearly you use AJAX to get the popup so i would first would make sure the ID of the edit button is the same as the ID from the item you want to open. Then you can do the following JS (using JQUERY)
$(".edit").on("click", function() {
var id = $(this).attr("id");
$.ajax({
type:"POST",
url: "controller/action/"+id;
success: function(data) {
//open dialog box and fill it with data
}
});
You could also add the id as data so you can get it with $_POST instead of it being a variable defined by the function. If you write the JS in a php document you can use $this->createUrl, but that is just whatever you prefer.
If with this you can not solve your problem then let us see how you implemented it right now.
i am not sure ... but i have a technique to do it....
if i have to do something like this ....
i will give class by htmlOptions and after that i will get value which should be an id to open popup..
example
<?php $this->widget('bootstrap.widgets.TbGridView', array(
'dataProvider' => $dataProvider ,
'type' => TbHtml::GRID_TYPE_BORDERED,
'template' => "{items}",
'columns' => array(
array(
'name' => 'vendor_configuration_id',
'header' => $dataProvider->model->getAttributelabel('vendor_configuration_id'),
'htmlOptions' => array('class'=>'idClass'),
),
array(
'name' => 'menu_type',
'header' => $dataProvider->model->getAttributelabel('menu_type'),
'htmlOptions' => array(),
),
?>
now jquery for it
$('.idClass').on("click",function(){
var neededId = $(this).html();
alert(neededId );
//openn popup based on this id or caal ajax to retrive data based on this
});

Customised query to display in CGridView in yii

Controller,
$model=Product::model()->display_products_statistics();
$this->render('admin',array(
'model'=>$model,
));
View,
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'product-grid',
'dataProvider' => $model->display_products_statistics(),
'filter'=> $model,
'columns'=> array(
'member_count',
'seller_count',
'visitor_count',
'lowest price',
'desc',
'price',
'createdate',
'updatedate',
'opid',
'pimg',
array(
'class'=>'CButtonColumn',
),
),
));
Model,
$sql="select member_count,seller_count,
visitor_count from fc_product fp
group by member_count,visitor_count,seller_count
order by member_count desc";
$connection=Yii::app()->db;
$command=$connection->createCommand($sql);
$products_statistics=$command->queryAll();
$dataprovider=new CArrayDataProvider($products_statistics,
array('pagination'=>false));
return $dataprovider->getData();
But then I am getting this error
Fatal error: Call to a member function getData() on a non-object in D:\wamp\www\yii\framework\zii\widgets\CBaseListView.php on line 111
I am confused and don't know what's going wrong.
Your problem is that you are not using CDataProvider in the correct way. CGridView needs an instance of CDataProvider to display, but you have used CDataProvider->getData() instead. I'd also recommend using CSqlDataProvider, which is purpose made for custom sql queries. Try this in your model;
$count = Yii::app()->db->createCommand('SELECT COUNT(*) FROM fc_product')->queryScalar();
$sql="select member_count,seller_count,
visitor_count from fc_product fp
group by member_count,visitor_count,seller_count
order by member_count desc";
return new CSqlDataProvider($sql, array(
'totalItemCount' => $count,
'sort' => array(
'attributes' => array(
'member_count', 'visitor_count', 'seller_count',
),
),
'pagination' => false

BootGridView Filter not working in Yii Framework

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.

Make pager appear at top of listing

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.