I use CGridView in Yii to create tables. I would like to show my table with pagination, but display summary text (i.e. Displaying 1-4 of 4 results.) at the bottom of grid. Is it possible in Yii?
You need to add this property to your array options widget:
'template'=>'{items}{summary}{pager}'
This is how it should look like:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'enablePagination' => true,
'template'=>'{items}{summary}{pager}',
'columns'=>array(...)
),
));
Yii docs - CBaseListView
'template'=>"{summary}\n{items}\n{pager}"
Related
I have a CGridView, one particular column is CLinkColumn. The footer for this column presently appears in plain text, I need it to be hyperlinked as well.
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$provider_sales,
'columns'=>array(
...,
array(
'header'=>'Status',
'class'=>'CLinkColumn',
'urlExpression'=>function($data){ return ...},
'footer'=> number_format($totals['status']),
),
),
));
How do I convert it to a hyperlink?
Now I just need one footer item to hyperlink, this could change tomorrow.
Hi You can simply use this CHtml::link in footer
'footer'=> CHtml::link(number_format($totals['status']),Yii::app()->createUrl("Your_Url"),array("target"=>"_blank")),
You can also pass param in this
CHtml::link('Link Text',array('controller/action',
'param1'=>'value1'));
For more info please read http://www.yiiframework.com/wiki/48/by-example-chtml/#hh0
i have a CgridView thats being loaded on ajax inside a modal, i want the pagers and filters to update the data via ajax (for now is just making an url request which changes the page to the url that only shows the cgridview). I know the widget has ajaxUpdate property but i don't know how to use it and i'm not sure if what i'm looking is what the property can do.
the widget:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'champions-grid',
'dataProvider'=>$dataProvider,
'itemsCssClass'=>'table',
'columns'=>array(
'Name',
'AttackDamage',
'AttackSpeed',
),
));
Update: I found out this widget uses it's own javascript library, but as it is being loaded via ajax (sorry for not to mention it earlier), the javascript is not loaded, however i know this won't tell how to make updates via ajax, i just thought i had to write this down here.
you would need to add
'ajaxUpdate'=>true,
So that code should look like
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'champions-grid',
'dataProvider'=>$dataProvider,
'ajaxUpdate'=>true,
'itemsCssClass'=>'table',
'columns'=>array(
'Name',
'AttackDamage',
'AttackSpeed',
),
));
I want to apply a different style for last entity of CListView , I noticed that there is a property "lastItemCssClass" for CMenu but this property does not exist for CListView. Someone would have an idea how to do this?
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemsTagName'=>'ul',
'summaryText' => '',
'enablePagination'=>false,
'itemView'=>'_viewItem',
));
?>
Without having more HTML and CSS available you may want to consider the last-child pseudo selector, refined around whatever your PHP's output HTML is.
I am trying to modify a table built using Yii boostrap and CactiveDataprovider, the table works fine but it automatically also displays the count of all items found, how to disable displaying this count
this is the view logic currently
$this->widget('bootstrap.widgets.TbListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'viewData'=>array('page'=>$page),
'itemsTagName'=>'table',
'itemsCssClass'=>'items table table-striped table-condensed',
'emptyText'=>'<i> Sorry, there are no active items to display</i>',
));
You need to add this line:
'template' => "{sorter}\n{items}\n{pager}",
TbListView extends from CListView, which uses the template variable to control the layout. See: http://www.yiiframework.com/doc/api/1.1/CListView#template-detail
The default template is "{summary}\n{sorter}\n{items}\n{pager}" where {summary} is what shows the count. So if you remove that, the count won't show
You might be reffering to: example
If so, set the template property as needed.
You need to delete the summary text.
pages stands for the pagination
items stands for ... the list of items
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'template' => "{summary}\n{pager}\n{items}\n{summary}\n{pager}",
'itemView' => '_index',
'pager' => array(
'maxButtonCount' => 10,
),
)
);
?>
It is easy.
put propriety summaryText false.
<?php $this->widget('bootstrap.widgets.TbListView',array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view_mercado',
'summaryText'=>false //make it for hide summary text
)); ?>
What about using CSS? is pretty straight forward
I got this alternative answer from an offline source, posting here for completeness.Both Ionut-flavius-Pogacian and frostyterrier methods worked and are better solutions as defining the template gives even more control over the widget behavior rather than just defining the summaryText as in the answer below
Tblistview is not documented in Yii-bootstrap documentation, but scanning the source it seems it is wrapper for CListview class in Yii.
CListview extends CBaseListView which has the summaryText property. Passing Blank data to it, removes the count which is active by default.
http://www.yiiframework.com/doc/api/1.1/CBaseListView#template-detail
SummaryText has the following usable variables
{start}: the starting row number (1-based) currently being displayed
{end}: the ending row number (1-based) currently being displayed
{count}: the total number of rows
{page}: the page number (1-based) current being displayed, available since version 1.1.3
{pages}: the total number of pages, available since version 1.1.3
{start} {end} and {count} are visible by default
The code could be modified to
$this->widget('bootstrap.widgets.TbListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'viewData'=>array('page'=>$page),
'itemsTagName'=>'table',
'itemsCssClass'=>'items table table-striped table-condensed',
'emptyText'=>'<i> Sorry, there are no active items to display</i>',
'summaryText'=>''
));
I want to display a loading image when I click on a sorting link of a listing record. Before, I used the complete property of Paginator. This works well if the table has more than one record.
My code is as follows:
<?php
$this->Paginator->options(array(
'update' => '#ourCompany-part',
'evalScripts' => true,
'before' => $this->Js->get('#loading')->
effect('fadeIn', array('buffer' => false)),
'complete' => $this->Js->get('#loading')->
effect('fadeOut', array('buffer' => false)),
));
?>
When the table has one record and we click on the sorting link of the paginator, it doesn't display the loading image. If the table has no records, then the index page is not loaded. How could I solve this?
Personally i don't like JsHelper i wrote jquery pugins or small function in my view. So check that the javascript looks like where you see 1 record or no record, it seems that helper not render javascitpt.