Simple widget for select Grid View page size

Yii 1.1 or above
// Extract and put PageSize folder into extensions directory // Place the widget just before the GridView <div align="right" class="row"> <?php $this->widget('application.extensions.PageSize.PageSize', array( 'mGridId' => '<grid-id>', //Gridview id 'mPageSize' => @$_GET['pageSize'], 'mDefPageSize' => Yii::app()->params['defaultPageSize'], 'mPageSizeOptions'=>Yii::app()->params['pageSizeOptions'],// Optional, you can use with the widget default )); </div> // Add below to your model search() 'pagination' => array( 'pageSize'=>Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']), ) // Add below to your config/main.php params 'defaultPageSize' = 10, 'pageSizeOptions'=>array(10=>10,20=>20,50=>50,100=>100), // Thats it.
Note: if you having issue with ajax submission fix this issue of framework
Total 8 comments
the page seems without any 'href' an empty link when i click in page2 for example nothing happen i used firebug and i found that there is a request with this parameter
what do you think is the problem?
how can i make it as header of cbutton column in cgridview?
@aruna470 about the dropdownlistHtmlOptions , i am not sure what's the best way to do that ;
you see in my code :
i originally thought the generated DropDownList can used in a form block ,and enven if the js is disabled the action of controller can handle it !
this is for unique porpus . multi wedget instances are possible !
one can use dropDownListHtmlOptions to register his/her onchange js eventHandler ,we shouldn't swollow it .(so i use a unique class for change event !)
so feel free to modify it . :)
@yiqing95 Thank you for your modifications. I will update them.
@aruna470 i never mind you use my new version as yours( as 2.0 ) :) , because this version is based on your works , feel free to use it in anywhere:
the usage is same to pageSize extension , in you index.php you may need a little modify :
you see every thing is ok . i just use the bootstrap extension and it works ,i didn't test the CListView ,but it should works too !
additionally you can give a htmlOptions for the CDropDownList , config the beforeLabel in your own language or just set it to empty string '' ;
it 's possible to use it in gii/giix to generate your admin view: and no need to modify your model class :
i v modified the original ext , want to support both CGridView and CListView ,but encounter some problem , the js function $.fn.yiiGridView.update/$.fn.yiiListView internal use this code to generate url: options.url = $.param.querystring(options.url, options.data); in pathInfo mode ,after you selected the pageSize and click some pageButton some thing strange happens , see the address of the pageLink such as : http://localhost/myProjName/user/admin/pageSize/5/ajax/user-grid/User_page/3?ajax=user-grid&pageSize=75
you see the latter pageSize will do not work
Good work!
Works beautifully with no problems, including ajax submission, in 1.1.8 (no need to do the 'fix' in 1.1.8)
Just make sure, 'files-grid' matches your cgridview's 'id'
Thx for the plugin!
Leave a comment
Please login to leave your comment.