Hello,
I am experiencing some pagination problems with CGridView when used with CSqlDataProvider (I can see the pagination gadget at the bottom of the grid but all rows show on page 1).
Here is how I create the data provider in the controller:
$connection=Yii::app()->db;
$sql="SELECT c.id, c.firstname, c.opcional, a.line1, a.line2, a.city, a.city, a.zip, a.state, a.type FROM CustomerName c LEFT JOIN Address a ON c.id = a.customerid;";
$rowcountsql = "SELECT COUNT(*) FROM CustomerName c LEFT JOIN Address a ON c.id = a.customerid;";
$command = $connection->createCommand($rowcountsql);
$count=$command ->queryScalar(); // provide count for pagination
// create data provider that works with CGridView
$dataProvider=new CSqlDataProvider($sql, array(
'totalItemCount'=>$count,
'pagination'=>array(
'pageSize'=>10,
),
));
$this->render(‘dynamic’,array(‘dataProvider’=>$dataProvider
));
And here is the code in the view:
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'customer-address-grid',
'dataProvider'=>$dataProvider,
'enablePagination'=>true,
'ajaxUpdate'=>true,
'enableSorting'=>true,
'columns'=>array(
'firstname:html:First Name',
'lastname:html:Last Name',
'opcional:html:Optional',
'line1:html:Line 1',
'line2:html:Line 2',
'city:html:City',
'state:html:State',
'zip:html:Zip',
'type:html:Type'
),
)); ?>
The view displays the grid just fine, I can see the pagination gadget at the buttom with
Go to page: < Previous 1 2 Next > which is correct (there are 15 rows in the sample database, and
I set pageSize to 10). The PROBLEM IS that I can see ALL ROWS on page 1, and nothing on page 2!!!
I am a noob, I just got started with yii. Could you tell me if I missed something or
there is a pagination issue when using CGridView with CSqlDataProvider? If I pass the model created by gii
to the view I do not have any problems. I suspect yiiGridView.js is missing a parameter, but debugging with
"inspector" proved not to be as fruitful as I thought it would be.
Any thoughts?
Thank you