No Pagination in CGridView

Dear All,

I have no success in setting no pagination in CGridView. What I do:

  1. Add this portion of code in the controller



         $details = new CActiveDataProvider('SalesDetail', array(

                    'criteria' => array(

                        'condition' => 'salesFk = :sFk',

                        'params' => array(':sFk' => $model->id),

                        ),

                     'pagination' => false));



  1. Add ‘enablePagination’ to ‘false’ in CGridView.

step 2 no problem, no pagination portion of the CGridView. Hoever, I got problem on step 1. Error because I set to false.

Any help on this?

Cheers,

Daniel

i’m not sure but i think it’s because the value of pagination is not a boolean but object.

u can use template in your gridview


'template'=>'{items}',

with this code you just show your table/gridview without paging and summarytext.

sorry for my bad english.

with enablePagination = false, it would not display the pagination, but the data is only shown as defined on the CAvticeDataProvider. It used to be worked fine in Yii 1.0.x. But now, in Yii 1.1.x, I cannot to make it work…

Thanks for your answer.

The ‘pagination’ => false in CActiveDataProvider without the enablePagination option works for the CGridView (just tested to be sure)…

Hi mdomba,

I got "Trying to get property of non-object" when doing this without enablePagination




$periodes = new CActiveDataProvider('Periode', array(

                    'criteria' => array(

                        'condition' => 'academicYearFk = :year',

                        'params' => array(':year' => $model->id),

                        'order' => 'shortName ASC',

                    ),

                    'pagination' => false,

                ));



Something wrong with my code?

It would help if you would check the stack trace… and find which object does generate this error…

for example in the above code this error can happen on $model->id if the variable $model is not an object…

Hi mdomba,

Below is the stack trace




Trying to get property of non-object

(C:\xampp-yski\xampp\framework\base\CComponent.php(619) : eval()'d code:1)

Stack trace:

#0 C:\xampp-yski\xampp\framework\zii\widgets\grid\CGridColumn.php(135):

BootDataColumn->renderDataCellContent()

#1 C:\xampp-yski\xampp\framework\zii\widgets\grid\CGridView.php(512):

BootDataColumn->renderDataCell()

#2 C:\xampp-yski\xampp\framework\zii\widgets\grid\CGridView.php(485):

BootGridView->renderTableRow()

#3 C:\xampp-yski\xampp\framework\zii\widgets\grid\CGridView.php(395):

BootGridView->renderTableBody()

#4 C:\xampp-yski\xampp\framework\zii\widgets\CBaseListView.php(158):

BootGridView->renderItems()

#5 unknown(0): BootGridView->renderSection()

#6 C:\xampp-yski\xampp\framework\zii\widgets\CBaseListView.php(141):

preg_replace_callback()

#7 C:\xampp-yski\xampp\framework\zii\widgets\CBaseListView.php(126):

BootGridView->renderContent()

#8 C:\xampp-yski\xampp\framework\web\CBaseController.php(166):

BootGridView->run()

#9

C:\xampp-yski\xampp\htdocs\yski_fee\protected\views\academicYear\view.php(77):

AcademicYearController->widget()

#10 C:\xampp-yski\xampp\framework\web\CBaseController.php(119): require()

#11 C:\xampp-yski\xampp\framework\web\CBaseController.php(88):

AcademicYearController->renderInternal()

#12 C:\xampp-yski\xampp\framework\web\CController.php(866):

AcademicYearController->renderFile()

#13 C:\xampp-yski\xampp\framework\web\CController.php(779):

AcademicYearController->renderPartial()

#14

C:\xampp-yski\xampp\htdocs\yski_fee\protected\controllers\AcademicYearController.php(40):

AcademicYearController->render()

#15 unknown(0): AcademicYearController->actionView()

#16 C:\xampp-yski\xampp\framework\web\actions\CAction.php(104):

ReflectionMethod->invokeArgs()

#17 C:\xampp-yski\xampp\framework\web\actions\CInlineAction.php(48):

CInlineAction->runWithParamsInternal()

#18 C:\xampp-yski\xampp\framework\web\CController.php(300):

CInlineAction->runWithParams()

#19 C:\xampp-yski\xampp\framework\web\filters\CFilterChain.php(134):

AcademicYearController->runAction()

#20 C:\xampp-yski\xampp\framework\web\filters\CFilter.php(41):

CFilterChain->run()

#21

C:\xampp-yski\xampp\htdocs\yski_fee\protected\modules\rights\components\RController.php(36):

RightsFilter->filter()

#22 C:\xampp-yski\xampp\framework\web\filters\CInlineFilter.php(59):

AcademicYearController->filterRights()

#23 C:\xampp-yski\xampp\framework\web\filters\CFilterChain.php(131):

CInlineFilter->filter()

#24 C:\xampp-yski\xampp\framework\web\CController.php(283):

CFilterChain->run()

#25 C:\xampp-yski\xampp\framework\web\CController.php(257):

AcademicYearController->runActionWithFilters()

#26 C:\xampp-yski\xampp\framework\web\CWebApplication.php(277):

AcademicYearController->run()

#27 C:\xampp-yski\xampp\framework\web\CWebApplication.php(136):

CWebApplication->runController()

#28 C:\xampp-yski\xampp\framework\base\CApplication.php(158):

CWebApplication->processRequest()

#29 C:\xampp-yski\xampp\htdocs\yski_fee\index.php(13):

CWebApplication->run()

REQUEST_URI=/yski_fee/academicYear/6



The thing is if I change the code to




$periodes = new CActiveDataProvider('Periode', array(

                    'criteria' => array(

                        'condition' => 'academicYearFk = :year',

                        'params' => array(':year' => $model->id),

                        'order' => 'shortName ASC',

                    ),

                    'pagination' => array(

                        'pageSize' => 20,

                    )

                ));



It will work just fine. It gives me a lot of headache…

From the error stack you can see that the error comes from renderdataCellContent() so the problem is with some column value…

one of your columns maybe has a relation value (like $post->author->name)… and on that record that fires the error… the relation does not have a value ($post->author is null)…

It works for you when you set 20 records… because the "error" record is somewhere after that… to check this try with a bigger number until you find the one that fires the error…

The result is only 14 rows, that’s why I set pagination to 20 to make all rows appear.

FYI, each academicYear will always has 14 periode.

I can’t help you more here…

My suggestion is to create a default CRUD with Gii and then set the pagination false… just so to see if it works… and then search/debug to find what is wrong with your code…

Help me, sir.

I have 45 data and I sort 23 data.

With pageSize 10.

My problems,

The pagination have 5 page, not 3 pages.

Have you this solve?

thanx, sir.