Yii Framework Forum: Synchronizing Two Pagers Clinkpager & Clistview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Synchronizing Two Pagers Clinkpager & Clistview Rate Topic: -----

#1 User is offline   Shaani 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 132
  • Joined: 17-July 12

Posted 13 November 2012 - 02:36 AM

In search view I have added two pagers for the user to move next or previous on the search result

 $this->widget('CLinkPager', array(
						'currentPage'=>$pages->getCurrentPage(),
'itemCount'=>$resultCount,
'pageSize'=> $page,
'header'=>'',
)) 


					
					$this->widget('zii.widgets.CListView',
						  array(
							  'dataProvider'=>$dataProvider,
							  'viewData'=>array('areaUnit'=>$areaUnit, 'areaType'=>$areaType, 'currencyUnit' => $currencyUnit, 'currencyType' => $currencyType),
							  'id'=>'postListView',
							  'enablePagination'=>true,
							  'enableSorting'=>false,
						      'itemView'=>'searchlist',
							)); 



if I click next on the pager of CLinkPager, the bottom pager which is of CListView also goes next. But if I click next on the bottom pager which is CListView's pager the ClinkPager's pager doesn't move to the next page. Can I just use CListView for showing two pagers one at the bottom and one at the top ?
0

#2 User is offline   skworden 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 14-June 12
  • Location:Virginia, USA

Posted 14 November 2012 - 05:46 PM

<?php $this->widget('zii.widgets.CListView', array(
        ..... your other code
	'template'=>'{pager}{items}<br/>{pager}',
        ..... your other code



will do the job


So in your case:


$this->widget('zii.widgets.CListView',array(
 'dataProvider'=>$dataProvider,
'viewData'=>array('areaUnit'=>$areaUnit, 'areaType'=>$areaType, 'currencyUnit' => $currencyUnit, 'currencyType' => $currencyType),
'id'=>'postListView',
'template'=>'{pager}{items}<br/>{pager}',                                                        'enablePagination'=>true,
'enableSorting'=>false,
'itemView'=>'searchlist',
 )); 

Note: you can use {summary}, {sorter}, {items} and {pager} here as many times as you like too. Just make sure you always have {items} and one {pager} because it will not use default settings by adding template and it would not show your data.

If you wanted 10 pagers you could. What ever is above (to the left) {items} will show above your list and whatever is below (to the right) will show below. You can also add html like above <br/>.


Pager Template Documentation
0

#3 User is offline   Shaani 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 132
  • Joined: 17-July 12

Posted 15 November 2012 - 03:27 AM

View Postskworden, on 14 November 2012 - 05:46 PM, said:

<?php $this->widget('zii.widgets.CListView', array(
        ..... your other code
	'template'=>'{pager}{items}<br/>{pager}',
        ..... your other code



will do the job


So in your case:


$this->widget('zii.widgets.CListView',array(
 'dataProvider'=>$dataProvider,
'viewData'=>array('areaUnit'=>$areaUnit, 'areaType'=>$areaType, 'currencyUnit' => $currencyUnit, 'currencyType' => $currencyType),
'id'=>'postListView',
'template'=>'{pager}{items}<br/>{pager}',                                                        'enablePagination'=>true,
'enableSorting'=>false,
'itemView'=>'searchlist',
 )); 

Note: you can use {summary}, {sorter}, {items} and {pager} here as many times as you like too. Just make sure you always have {items} and one {pager} because it will not use default settings by adding template and it would not show your data.

If you wanted 10 pagers you could. What ever is above (to the left) {items} will show above your list and whatever is below (to the right) will show below. You can also add html like above <br/>.


Pager Template Documentation




<?php 
					$this->widget('zii.widgets.CListView',
						  array(
							  'dataProvider'=>$dataProvider,
						      'itemView'=>'searchlist',
							  'id'=>'postListView',
							  'template'=>'<div class="main-detail-con" style="width:700px;">
				<div style="width:700px; padding-left: 0px; text-align:center;" class="listing-center-numbers">			
					{pager}
				</div>
			</div><div class="clear"></div>{summary}{items}<br/>{pager}',   
							  'enablePagination'=>true,
							  'enableSorting'=>false,
							)); ?>



Thanks. That worked. My code had if statement for creating a bottom border in the div of the first pager.



Previously I had this code for the first pager

<?php if ($resultCount > 0){ ?>
			<div class="main-detail-con" style="width:700px;">
				<div style="width:700px; padding-left: 0px; text-align:center;" class="listing-center-numbers">			
					<?php $this->widget('CLinkPager', array(
						'currentPage'=>$pages->getCurrentPage(),
						'itemCount'=>$resultCount,
						'pageSize'=> 10,
						'header'=>'',
					)) ?>
				</div>
			</div><?php } ?>	   
          <div class="clear"></div>





I don't want to output this div if there are no search results <div style="width:700px; padding-left: 0px; text-align:center;" class="listing-center-numbers">. Like the <br /> how can I use php variables in the template ? I tried $hello but it outpts $hello, not the variable's value. I'm thinking of assigning the div and {pager} to a variable and using that variable in template between {summary} {items} .... OR is there another way to do it ?
0

#4 User is offline   skworden 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 14-June 12
  • Location:Virginia, USA

Posted 16 November 2012 - 01:26 AM

I would tell it what to do if there aren't results. Maybe some default empty div to not mess up your styling or some other code. Something along the lines of
<?php 
    if ($resultCount > 0) {
        echo 'your divs and widget';
    }
    else {
	echo ' Whatever you want to show or leave blank ';
}
; ?>


or assign it to a var and

<?php 
    if ($resultCount > 0) {
        echo $myvar1;
    }
    else {
	echo $myemptyvar;
}
; ?>



or just assing the whole thing and in your view just
<?php
 echo $whateveryoucallit;
?>


I would do the second/third. Also, personally I would put the all the styles in your css file too.

.main-detail-con{
        width:700px;
        padding-left: 0px; 
        text-align:center;
	...the rest of you styles
}
and just have
<div class"main-detail-con>
.....your stuff 
</div>



The second/third way & doing the css that way is cleaner and would be less confusing to someone else looking at it. Two if your style is messed up you just have to go to one place to fix it /or change it instead of searching for it in a bunch of different places.

The first way is job security ;) and potential headache.
However, just do whatever you are most comfortable doing.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users