text instead of icons on TbButtonColumn using Yii-Booster - php

I'm using TbButtonColumn to render some icon buttons. I want to render text instead of the icons. Is this possible and how would I alter the following code to do this?
$gridColumns = array(
array('name'=>'nick_name', 'header'=>'Interests Sets'),
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{add} {view}',
'buttons'=>array(
'add' => array
(
'label'=>'See this friend\'s list',
'icon'=>'plus',
'url'=>'Yii::app()->createUrl("itemList/viewlist", array("friend_id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),
'view' => array(
'label'=>'Search under this friend\'s interesrs',
'url'=>'Yii::app()->createUrl("friend/filter", array("friend_id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),
),
)
);

I know nothing about yii-booster, but if it's anything like Yii's CButtonColumn, you only need to set the imageUrl to false. Like this:
'view' => array(
'imageUrl'=>false, // Setting an empty string does not work in vanilla Yii.
'label'=>'Search under this friend\'s interesrs',
'url'=>'Yii::app()->createUrl("friend/filter", array("friend_id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),

$gridColumns = array(
...
'buttons'=>array(
'add' => array
(
'label'=>'text instead of the icons' . 'See this friend\'s list',
'url'=>'Yii::app()->createUrl("itemList/viewlist", array("friend_id"=>$data->id))',
'options'=>array(
'class'=>'btn btn-small',
),
),
),
)
);
if you set 'icon'=>'ololo', run this code:
if (isset($this->icon))
{
if (strpos($this->icon, 'icon') === false)
$this->icon = 'icon-'.implode(' icon-', explode(' ', $this->icon));
$this->label = '<i class="'.$this->icon.'"></i> '.$this->label;
}

Related

CArrayDataProvider in YII sorting not working on some fields

I have created Dataprovider in controller and pass it to view file. It display correct Data. There are total 7 columns to display.
But only on 2 fields sorting is not working and throwing ERROR-500.
In controller File, my Code is :
$OutboundRatecardDetails_data = OutboundRatecardDetails::model()->findAllByAttributes(array('orc_id'=>$orc_id));
$pageSize = 10;
if(isset($_GET['pageSize']))
{
$pageSize = $_GET['pageSize'];
Yii::app()->user->setState('pageSize', (int)$_GET['pageSize']);
unset($_GET['pageSize']);
}
$dataProvider=new CArrayDataProvider($OutboundRatecardDetails_data, array(
'id'=>'orcd_id',
'sort'=>array(
'attributes'=>array(
'orcd_id', 'des_id', 'orcd_duration','orcd_rate','orcd_grace_duration','orcd_description'
),
),
'pagination'=>array(
'pageSize'=>$pageSize,
),
'keyField'=>'orcd_id',
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
In admin.php view file, my code is :
<?php $this->widget('application.components.widgets.tlbExcelView', array(
'id'=>'Outbound-rate-card-details-grid',
'dataProvider' =>$dataProvider,
'itemsCssClass' =>'table table-bordered table-striped table-condensed',
'pagerCssClass' =>'dataTables_paginate paging_bootstrap pagination',
'htmlOptions' =>array('class'=>'adv-table'),
'columns'=>array(
'des_id'=>array(
'name'=>'des_id',
'header'=>'Destination',
'value' => '(!empty($data->rel_destination->des_prefix) ? $data->rel_destination->des_prefix : "")',
),
array(
'name'=>'orcd_grace_duration',
'header'=>'Grace Duration',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_duration',
'header'=>'Incr. Duration',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_rate',
'header'=>'Incr. Rate',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_min_duration',
'header'=>'Min. Duration',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_min_rate',
'header'=>'Min. Rate',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_description',
'header'=>'Rate Description',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
),
)); ?>
When I try to sort on 2nd and 3rd field (orcd_grace_duration,orcd_duration), it throws error. Error screenshot is also attached. Other than these 2 fields, sorting is perfectly working.
This issue occurs when CArrayDataProvider's columns having same values.
Try using CActiveDataPrider instead.
You just need to change code in your controller like below:
$criteria = new CDbCriteria;
$criteria->compare('orc_id',$orc_id,true);
$dataProvider = new CActiveDataProvider('OutboundRatecardDetails', array(
'criteria'=>$criteria,
'sort' => array(
'defaultOrder' => 'orc_id desc',
),
'pagination'=>array(
'pageSize'=>$pageSize,
),
));

How can I change cbuttoncolumn label dynamically in yii cgridview

I am trying to change cbuttoncolumn label dyanamically. But somehow it does not work. My code is
array(
'class'=>'CButtonColumn',
'template'=>'{publish}',
'buttons'=>array(
'publish'=>array(
//'type'=>'raw',
'label'=>'$data->content_type == 1 ? "View & Publish" : "Publish"',
'icon'=>'ok',
'url'=>'Yii::app()->createUrl("/admin/contentToPublish/publish")',
),
),
),
How can i do this??
You can just create a new column with custom links, something like this:
In your model :
public function getMyValue(){
$linkOne = CHtml::link("$this->labelOne", Yii::app()->createUrl("model/action",array("id"=>$this->id)));
$linkTwo = CHtml::link("$this->labelTwo", Yii::app()->createUrl("model/action",array("id"=>$this->id)));
return $linkOne.' '.$linkTwo;
}
And in your CGridView :
'columns'=>array(
'labelOne',
'labelTwo',
array(
'type' => 'raw',
'header' => 'Manage',
'value' => '$data->getMyValue()',
),
),
Or, you can use the visible attribute in CButtonColumn:
array(
'class'=>'CButtonColumn',
'template'=>'{publish}{viewPublish}',
'buttons'=>array(
'publish'=>array(
//'type'=>'raw',
'label'=>'Publish',
'visible' => '$data->content_type != "1"',
'icon'=>'ok',
'url'=>'Yii::app()->createUrl("/admin/contentToPublish/publish")',
),
'viewPublish'=>array(
//'type'=>'raw',
'label'=>'View & Publish',
'visible' => '$data->content_type == "1"',
'icon'=>'ok',
'url'=>'Yii::app()->createUrl("/admin/contentToPublish/publish")',
),
),
),
Hope that helps :)

Listing only the particular data value in Tbgridview of yii

I have an attribute, idC, which may contain any positive integer number.
So, If idC has values like 2,3, and so on such that 3 comes 4 times and 2 comes 2 times.
Now, I want to list out data values with only idC=3 for one page
and idC=2 for another page and so on.
But how to do this.
Here is the listing code:
<?php
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'Subjects-grid',
'dataProvider'=>$model->search(),
'type'=>'striped bordered condensed',
'template'=>'{summary}{items}{pager}',
'columns'=>array(
array('header'=>'<a>S.N.</a>',
'value'=>'$data->id_subjects',
'htmlOptions'=>array('width'=>'70px'),
),
'idC=$idC',
array(
'header'=>'<a>Subject</a>',
'value'=>'$data->subject',
),
'staff_type',
'sub_subject',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
'header'=>'<a>Actions</a>',
'template' => '{view} {update}',
'buttons' => array(
'view' => array(
'label'=> 'View',
'options'=>array(
'class'=>'btn btn-small view'
) ),
'update' => array(
'label' => 'Update',
'options' => array(
'class' => 'btn btn-small update'
)
),
),
'htmlOptions'=>array('nowrap'=>'nowrap'),
)
),
)); ?>
and here's the view page.

Include a pagination and summary text alone before gridview in YII

I want show pagination before gridview content. i tried renderPager() I cannot get widget object call the method
code here...
$gridview = $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$expirations,
'id'=>'image-grid-list',
'itemsCssClass'=>'table collections',
'ajaxUpdate'=>true,
'template'=>'{items}{summary}',
'pager'=>array(
'class'=>'CLinkPager',
'header'=>'',
),
'columns'=>array
(
array(
'class'=>'CCheckBoxColumn',
'selectableRows' => null,
'name'=>'image_id',
"value"=>'$data->image_id',
"id"=>"expirations",
"htmlOptions"=>array("style"=>"width:30px;")
),
array(
'name'=>'',
'type'=>'html',
'value'=>'
(!empty($data->image_title))?CHtml::image("/".Yii::app()->params["imagePath"]."/".$data->catalog->catalog_title."/thumb_".$data->image_title,"",array()):"no image"',
'header'=>''
),
array(
'name'=>'image_title',
'type'=>'raw',
'value'=>'CHtml::link($data->catalog->catalog_title."/".$data->image_title,"javascript:void(0);")."<br>#".$data->image_id."<br/><br/> Number of light boxes ".$data->collection_count." <br/><br/> Number of downloads ".$data->downloaded_count ',
'header'=>'Title'
),
array( // display 'author.username' using an expression
'name'=>'copyright_expiration_date',
'type'=>'raw',
'value'=>'(!empty($data->copyright_expiration_date))?date("m-d-Y",$data->copyright_expiration_date):"-"',
'header'=>'Rights expiration date'
),
array( // display 'author.username' using an expression
'name'=>'copyright_type',
'type'=>'raw',
'value'=>'$data->copyright_type',
'header'=>'Rights'
),
array( // display 'author.username' using an expression
'name'=>'',
'value'=>'$data->usage_and_terms',
'header'=>'Usage and terms'
),
array( // display 'create_time' using an expression
'name'=>'photographer_name',
'value'=>'$data->photographer_name',
'type'=>'raw',
'header'=>'Photographer name'
),
),
),true);
$gridview->renderPager();
I cannot call the method .. I want create widget object , call renderContent, renderPager etc
use template attribute.
'template' => '{pager}{items}{summary}',
eg.,
$gridview = $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$expirations,
'id'=>'image-grid-list',
'itemsCssClass'=>'table collections',
'ajaxUpdate'=>true,
'template' => '{pager}{items}{summary}',
'pager'=>array(
'class'=>'CLinkPager',
'header'=>'',
),
'columns'=>array
(
......

how to Pop Up A New Windwon In Gridview?

How to Pop Up A New Windwon In Gridview?
When the use click the refund button of gridview, I would like to display the popup box with the data. How can I do?
This is the my gridview
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'advance-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array('name' => 'acc_category_id',
'value'=>'(isset($data->acccategories->name)) ? CHtml::encode($data->acccategories->status) :"Not Set"',
'filter'=>CHtml::listData($acccate, 'id', 'name'),
),
array('name' => 'accmain_id',
'value'=>'(isset($data->accmains->name)) ? CHtml::encode($data->accmains->name) :"Not Set"',
'filter'=>CHtml::listData($accmain, 'id', 'name'),
),
array('name' => 'job_id',
'value'=>'(isset($data->jobs->name)) ? CHtml::encode($data->jobs->name) :"Not Set"',
//'filter'=>CHtml::listData($job, 'id', 'name'),
),
'currency',
'amount',
array('name' => 'created_date',
'value'=>'Yii::app()->dateFormatter->format("d MMM y",strtotime($data->created_date))',
// 'filter'=>CHtml::listData($job, 'id', 'name'),
),
array(
'class'=>'CButtonColumn',
'template'=>'{update} {delete} {refund}',
'buttons'=>array
(
'update' => array
(
'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/edit.gif',
'options'=>array('style'=>'width:10px; border:none;'),
'url'=>'Yii::app()->createUrl("advance/update", array("id"=>$data->id))',
),
'delete' => array
(
'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/delete.gif',
'options'=>array('style'=>'width:10px; border:none;'),
'url'=>'Yii::app()->createUrl("advance/delete", array("id"=>$data->id))',
),
'refund' => array
(
'type'=>'raw',
'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/icon_refund_loans2.gif',
'options'=>array('style'=>'width:10px; border:none;'),
'url'=>'Yii::app()->createUrl("advance/view", array("id"=>$data->id))',
),
),
),
),
'htmlOptions' => array(
//'class' => 'table table-bordered table-striped table_vam grid_widget',
),
)); ?>
<div id="loadingdiv" style="float:right; margin-right:160px;"> </div>
<div id="jobslist"></div>
=====================================
update
when I update the grid by following and check by firebug, it is displaying the data at firebug. but not display popup.
array(
'header'=>'Refund',
'type'=>'raw',
'value'=>'CHtml::ajaxLink($data->id, array("advance/jobslist", "id"=>$data->id), array("onclick"=>\'$("#jobslist").dialog("open"); return false;\'));',
),
This is controller
public function actionJobslist()
{
$model=new Job('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Customer']))
$model->attributes=$_GET['Customer'];
if(isset($_GET['AccRecei']))
$accrecei->attributes=$_GET['AccRecei'];
$this->renderPartial('jobs_listing',array('model'=>$model),false,true);
}
this is view/jobs_listing.php
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'jobslist',
'options'=>array(
'title'=>Yii::t('job','Jobs List'),
'autoOpen'=>true,
'modal'=>'true',
'width'=>'750',
'height'=>'500',
),
));
echo $this->renderPartial('_jobs_listing', array('model'=>$model)); ?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
how should I do?
array(
'header'=>'Refund',
'type'=>'raw',
'value'=>'CHtml::link($data->id, array("id"=>$data->id, 'class'=>'view-popup'));',
),
and insert javascript:
$('.view-popup').live('click', function() {
var id = $(this).attr('id');
window.open("<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/your_path/id/'; ?>" + id,'popUpWindow','height=800,width=1000,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
return false;
});
Inner of the grid
array(
'header'=>'Refund',
'type'=>'raw',
'value'=>'CHtml::ajaxLink($data->id, array("advance/jobslist", "id"=>$data->id), array(
"onclick"=>"$(\"#jobslist\").dialog(\"open\"); return false;","update"=>"#jobslist",
"beforeSend" => "function() {
$(\"#loadingdiv\").addClass(\"ajaxloading\");
}",
"complete" => "function() {
$(\"#loadingdiv\").removeClass(\"ajaxloading\");
}",
),array("id"=>"showcustomerlist2"));',
),
Out of the grid
<div id="loadingdiv" style="float:right; margin-right:160px;"> </div>
<div id="jobslist2"></div>

Categories