Include a pagination and summary text alone before gridview in YII - php

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
(
......

Related

Decimal Format in Yii TBGridview

I have code like this :
<?php
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'appliances-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'price',
'type'=>'number',
'htmlOptions'=>array('style' => 'text-align: right;'),
),
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{update}{delete}'
),
),
));
?>
the result is integer number only and search filter is work, how to change it into decimal format but search filter still working ?
I tried to change it into :
array(
'name'=>'price',
'type'=>'number',
'htmlOptions'=>array('style' => 'text-align: right;'),
'value'=>function($data)
{
return number_format($data->price,2,',','.');
},
),
But it makes search filter not working properly.
I found the answers here :
Yii Number Formatting
How to format numeric string using C.Gridview - Yii
And also I found this link Yii , show different date format in cgridview
Try This:-
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'cost', // display the 'cost' attribute
array( // display the 'cost_in_dollars' using an expression
'name' => 'cost_in_dollars',
'value' => 'number_format($data->cost/100, 2)',
),
),
));

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.

How create sort option for Yii gridview custome column fields

I want do sort for custome column fields for table fields its working fine, clinkcolumn fields or customs fields not working
<?php
$this->widget('zii.widgets.grid.CGridView',
array(
'dataProvider'=>$dataProviderInActive,
'id'=>'collections-grid-inactive',
'itemsCssClass'=>'table collections',
'ajaxUpdate'=>true,
'pager'=>array(
'class'=>'CLinkPager',
'header'=>'',
),
'columns'=>array
(
array(
'class'=>'CLinkColumn',
'labelExpression'=>'$data->collection_title',
'urlExpression'=>'Yii::app()->createUrl("",array("collection"=>$data->collection_title))',
'header'=>'Catalog Title'
),
array( // display 'author.username' using an expression
'name'=>'Number of Images',
'value'=>'',
),
array( // display 'author.username' using an expression
'name'=>'Number of images used in lightboxes',
'value'=>'0',
),
array( // display 'author.username' using an expression
'name'=>'Number of expired',
'value'=>'0',
),
array( // display 'create_time' using an expression
'name'=>'Date Created',
'value'=>'date("Y-m-d", $data->created_at)',
),
array( // display a column with "view", "update" and "delete" buttons
'class'=>'CButtonColumn',
'template'=>'{view}{edit}{delete}{expiration_report}',
'buttons'=>array
(
'view' => array
(
'label'=>'view',
'options'=>array('class'=>'btn'),
'imageUrl'=>'',
'url'=>'Yii::app()->createUrl("",array("collection"=>$data->collection_title))',
),
'edit' => array
(
'label'=>'edit',
'options'=>array('class'=>'btn'),
'imageUrl'=>'',
'url'=>'Yii::app()->createUrl("", array())'
),
'delete' => array
(
'label'=>'delete',
'options'=>array('class'=>'btn-danger btn'),
'imageUrl'=>'',
'url'=>'Yii::app()->createUrl("", array())'
),
'expiration_report' => array
(
'label'=>'expiration report',
'options'=>array('class'=>'btn'),'imageUrl'=>'',
'url'=>'Yii::app()->createUrl("", array())'
),
)
),
),
));
?>
Try adding the attribute in the sort attributes array:
$dataProviderInActive->sort->attributes['collection_title']=array(
'asc'=>'collection_title',
'desc'=>'collection_title DESC');
Your question doesn't have the full details. If this is a custom field, you will have to explicitly define the sorting based on the object type. For example, I did this for CArrayDataProvider objects, and here it is. You will need to do this in your model. Again, the answer will depend on the object type. In my example, $rawData was the returned data from a database query.
return new CArrayDataProvider($rawData, array(
'id'=>'id',
'sort'=>array(
'attributes'=>array(
'attribute1',
'attribute2',
),
),
'pagination'=>array(
'pageSize'=>50,
),
));

text instead of icons on TbButtonColumn using Yii-Booster

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;
}

Categories