Cgridview Without Pagination And Record Limit

I have a CGridView with some data to display in it. I want to disable pagination and limit number of rows that can be displayed. I use the code:


'enablePagination' => false



and it did a half of the job: the paginator is gone, but the problem is that the grid shows now in summary that total number of records is equal to the page size. That’s not true. I need that total number of records to be reported correctly.

For example, if pageSize is 5 and there exist 7 records, CGridView reports "Displaying 1-5 of 7 results." when pagination is enabled, but it shows "Total 5 results." when pagination is disabled. I played with summaryText template, but it seems that {count} is incorrect when pagination is disabled.

In other words, is there a way to always have the summary "Displaying 1-5 of 7 results." irrespective to the fact if pagination is enabled?

you have to do this in dataprovider




$data= new CActiveDataProvider($model, array(

            'pagination'=>false,

		));



or




$data= new CActiveDataProvider($model);


$data->setPagination(false);



Hi I am not sure if this what you looking for, it shows five records and shows 100000 records in summary


$dataProvider=new CActiveDataProvider('Model', array(

      'pagination' => array('pageSize' => 5),

      'totalItemCount'=>'100000'

    ));

This does not solve the problem. When I disable pagination in the data provider, I lost a possibility to limit number of records on a page via pageSize, and I see all records listed.

Moreover, this data provider is used by several pages, and I need to disable pagination only in one of them.

Yes, this is not what I’m looking for. This will preserve pagination, while I need to suppress it, totalItemCount should be automatically assigned from DB as it was with enabled pagination.

Currently I hide incorrect summary via summaryCssClass as a workaround.

Dear Friend

I do not have any option other than overiding the CGridView.

components/GridView.php




<?php

Yii::import('zii.widgets.grid.CGridView');

class GridView extends CGridView

{	


public function renderSummary()

{   

		

	if(($count=$this->dataProvider->getItemCount())<=0)

		return;


	echo '<div class="'.$this->summaryCssClass.'">';

	if($this->enablePagination)

	{

		$pagination=$this->dataProvider->getPagination();

		$total=$this->dataProvider->getTotalItemCount();

		$start=$pagination->currentPage*$pagination->pageSize+1;

		$end=$start+$count-1;

		if($end>$total)

		{

			$end=$total;

			$start=$end-$count+1;

		}


		if(($summaryText=$this->summaryText)===null)

		$summaryText=Yii::t('zii','Displaying {start}-{end} of 1 result.|Displaying {start}-{end} of {count} results.',$total);

		echo strtr($summaryText,array(

			'{start}'=>$start,

			'{end}'=>$end,

			'{count}'=>$total,

			'{page}'=>$pagination->currentPage+1,

			'{pages}'=>$pagination->pageCount,

			));

	}

	else

	{

               if(($summaryText=$this->summaryText)===null)

		$summaryText=Yii::t('zii','Total 1 result.|Total {count} results.',$count);

		echo strtr($summaryText,array(

			'{count}'=>$count,

			'{start}'=>1,

			'{end}'=>$count,

			'{page}'=>1,

			'{pages}'=>1,

			'{totalCount}'=>$this->dataProvider->getTotalItemCount(),//this is the added line.

			));

	}

		echo '</div>';

	}

	

}

?>




The widget.




<?php $this->widget('GridView', array( //GridView 

	'id'=>'worker-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'enablePagination'=>false,

	'summaryText'=>'{count} out of {totalCount} items', //declare our new totalCount...

        'columns'=>array(




)



The dataprovider.




return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

			'pagination'=>array('pageSize'=>5)

		));



Regards.