Yii CListView pager stretches to much - yii

I used Yii CListView widget to paginate thru results.
I have a container div with position:relative and float:left.
I have 2 div's, each with float:left inside the container.
The problem is that if I have to many pages with results, the seccond div falls under the first div.
I need them both, on the same line, as ishown in image 2.
Does yii's clistview have a property that sets the maximum number of pages to be echoed in the pager?
I don't need the clistview to print the pages from 60 to 69; from 60 to 65 is enought, so a limit of 6 should be enought.
Any ideas?

You have to set maxButtonCount attribute of CLinkPager to 5. The CLinkPager attributes can be specified through pager attribute of CListView
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_item_view',
'pager'=>array(
'class'=>'CLinkPager',
// This attribute species how many buttons are displayed
'maxButtonCount'=>5
),
.....,
.....
));

you could just pass it in the pager property and it'd override the default value :'pager' => array(
'maxButtonCount' => 5
),

Related

How to set items per page dropdown in grid view for yii

I want to set items per page dropdown in yii gridview.
What changes i need to do this? Has anyone had implemented this type of functionality before?
You have to add summaryText entry to the gridview as below.
$pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider_countries,
'summaryText'=>'Displaying {start}-{end} of {count} result(s). ' .
CHtml::dropDownList(
'pageSize',
$pageSize,
Yii::app()->params['pageSizeOptions'],
array('class'=>'change-pageSize')) .' rows per page',
Result is similar to following.

Div id conflict in ClistView yii 1

I am working on a Yii project,on the index page i have multiple div id's loaded by the yii the first id is named yw0 and second is yw1 and third is yw2,but after the yw1 id i have a ajax page which also generates two id's yw0 and yw1. so the new id's are conflicting with the old one what will will be the possible solution to get rid of this.
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dp,
'itemView'=>'_view',
'id'=>'id-of-list-view-div',
'pager'=>array(
'id'=>'id-of-pager-ul'
)
));
You can set your own html ID on both widgets (CListView and CPager)
This way when they are reloaded they will keep the IDs and there will be no conflict
Hope it helps

How i dont display empty and null rows in yii

How I do not display empty and null rows in yiiframework with listview.
Many rows in database are null.When I want to show data in view.php I see many null rows.I see a data on the other page.
can I see just rows with data.
The CListView widget uses a template to render each row of data.
In the skeleton generated by Gii, the index.php file has a CListView widget that uses the _view.php file to display row data.
You only have to check if a field is null and don't show it.
If you are aking for the autogenerated view.php file, the default is CDetailView
At this place, you can use the "visible" element of the attribute item:
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
array(
'name'=>'field1',
'visible'=>$model->field1!=null,
),
..............
See attributes property of CDetailView and CListView
in your model, put a condition to filter null/empty values before rendering the result to your view.
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('table_column', $this->tableColumn, false );
$criteria->condition .= "another_table_column IS NOT NULL"; //this will filter null values
Use the afterFind() method in your Model to change the value displayed in the view so that a null value is shown as "NA" or some other value like that.

Yii ClistView Pagination set number of page shown in Pager

Hi think this is a quite easy problem, but I can't find the solution in the docs. I'm using Yii ClistView to paginate my results and everything works great, simply (as I could have a lot of results) I would like to limit non the result but the page shown in the navigation (that are ten by default) to let's say 4. But I won't limit the number of my results, just when I reach the 4th page the navigation will slide (as its default behavior) to show page 5, 6, ecc...
Is this possible? Does anyone have advice?
Thanks in advance!
How about setting pager's maxButtonCount like this:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
// ...
'pager' => array('maxButtonCount' => 4),
));

Hidden Pagination summary text

I use CGridView in Yii to create tables.
I would like to show my table with pagination but hide the summary text at the top, which indicates the number of page restance (Displaying 1-4 of 4 results.)
Is that possible?
thank you
Sorry for my English
There is a template option. By default it equals {summary}\n{items}\n{pager}
If you override it in your gridview config, you'l be able to remove summary section:
$this->widget(
'zii.widgets.CGridView',
array(
Your options here ...
'template' => '{items}\n{pager}',
)
);
Another option is to set the CGridView summaryText value to false
Because YII uses CListView, it also add a certain summary class CSS in the asset folder. So to combat this, simply override the css.
Add this to your CSS.
#yw0>.summary{
display:none;
}