I have a strange pagination problem. I declare pagesize=20, but first page i got 10 data, second page blank, third page 3 and so on. I have no idea where is my problem. Here is my controller
public function actionAdmin()
{
$this->processAdminCommand();
$criteria=new CDbCriteria;
$pages=new CPagination(Book::model()->count($criteria));
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
$sort=new CSort('Book');
$sort->applyOrder($criteria);
$models=Book::model()->findAll($criteria);
//$model->lab_id = Yii::app()->user->id;
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/jquery.tools.js');
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/jquery-impromptu.js');
Yii::app()->clientScript->registerScript('tabs',$this->_tabScript, 4);
$this->render('admin',array(
'models'=>$models,
'pages'=>$pages,
'sort'=>$sort,
));
//}
}
view file
<table class="dataGrid">
<thead>
<tr>
<th>Actions</th>
<th><?php echo $sort->link('User_id'); ?></th>
<th><?php echo $sort->link('name'); ?></th>
<th><?php echo $sort->link('phone'); ?></th>
<th><?php echo $sort->link('book'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach($models as $n=>$model): ?>
<?php if ($model->User_id >= '1'){ ?>
<tr class="<?php echo $n%2?'even':'odd';?>">
<td> <?php echo CHtml::ajaxLink('test',array('update','id'=>$model->id),array('success'=>"function(data) {
$.prompt(data, {
buttons: {Cancel: true } }) }")); ?>
<?php echo CHtml::linkButton('Delete',array(
'submit'=>'',
'params'=>array('command'=>'delete','id'=>$model->id),
'confirm'=>"Are you sure to delete #{$model->id} - {$model->book}?")); ?>
</td>
<td><?php echo CHtml::activeDropDownList($model, 'User_id',CHtml::listData(CActiveRecord::model('User')->findAll(),'id','loginName'),array('disabled'=>true)); ?></td>
<td><?php echo CHtml::encode($model->name); ?></td>
<td><?php echo CHtml::encode($model->phone); ?></td>
<td><?php echo CHtml::encode($model->book); ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
</tbody>
</table>