Yii Framework Forum: Numbering Clistview Results - Yii Framework Forum

Jump to content

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

Numbering Clistview Results Rate Topic: -----

#1 User is offline   swampone 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 28-March 11

Posted 21 January 2013 - 09:53 PM

Is there an easy way to number each record and label each with like 1, 2, 3 or better yet 1st, 2nd, or 3rd generated by ClistView. Here is my ClistView
$this->widget('zii.widgets.CListView', array(
                            'dataProvider'=>$dataProvider,
                            'itemView'=>'_view',
                            'emptyText'=>'There are no clients  waiting in line',
               
                            'summaryText'=>'There are {count} clients waiting in line',

                    ));

0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 21 January 2013 - 11:11 PM

Dear Friend

We can do something like this.

index.php
<?php $this->widget('zii.widgets.CListView', array(
	'dataProvider'=>$dataProvider,
	'itemView'=>'_view',
	'viewData'=>array("dataProvider"=>$dataProvider),
)); ?>


_view.php
<?php
 $itemNumber=($dataProvider->pagination->pageSize*$dataProvider->pagination->currentPage)+array_search($data,$dataProvider->getData())+1;
?>
div class="view">
   
	<?php echo CHtml::encode($itemNumber); ?>
	<br />

<!-- below all the routine attributes -->

	<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
	<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>
	<?php echo CHtml::encode($data->name); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('mark')); ?>:</b>
	<?php echo CHtml::encode($data->mark); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('rank')); ?>:</b>
	<?php echo CHtml::encode($data->rank); ?>
	<br />


</div>

We can also calculate itemNumber in the following way.
($dataProvider->pagination->pageSize*$dataProvider->pagination->currentPage)+$index+1;
//$index is provided by the dataprovider for current item.


Regards.
1

#3 User is offline   swampone 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 28-March 11

Posted 21 January 2013 - 11:41 PM

View Postseenivasan, on 21 January 2013 - 11:11 PM, said:

Dear Friend

We can do something like this.

index.php
<?php $this->widget('zii.widgets.CListView', array(
	'dataProvider'=>$dataProvider,
	'itemView'=>'_view',
	'viewData'=>array("dataProvider"=>$dataProvider),
)); ?>


_view.php
<?php
 $itemNumber=($dataProvider->pagination->pageSize*$dataProvider->pagination->currentPage)+array_search($data,$dataProvider->getData())+1;
?>
div class="view">
   
	<?php echo CHtml::encode($itemNumber); ?>
	<br />

<!-- below all the routine attributes -->

	<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
	<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>
	<?php echo CHtml::encode($data->name); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('mark')); ?>:</b>
	<?php echo CHtml::encode($data->mark); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('rank')); ?>:</b>
	<?php echo CHtml::encode($data->rank); ?>
	<br />


</div>

We can also calculate itemNumber in the following way.
($dataProvider->pagination->pageSize*$dataProvider->pagination->currentPage)+$index+1;
//$index is provided by the dataprovider for current item.


Regards.


Yesss! Thanks!
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