Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Very Easy 'jump To Page' Addition To Cgridview

$
0
0
I have been looking for a 'Jump to page' function in the pager, but couldn't find it in the docs. The only thing I found in the forum when searching for 'Jump to page' was a Spanish page.

Since I came up with a quick and dirty but realy simple solution, I'll share it with you, hoping it will be improved.

I'm using the Gii CRUD code in the admin view. Just above the CGridView code add:
<?php 
echo CHtml::textField(ucfirst(Yii::app()->controller->id)."_page",'0',
		array('id'=>'jump-to-page',
	));
?>
// The CRUDded CGridView
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id' => 'user-grid',
	'dataProvider' => $model->search(), ETC.....


and add to your jQuery

$('#jump-to-page').change(function(e){
	$.fn.yiiGridView.update('user-grid', {
		data: $(this).serialize()
	});
	e.preventDefault();
});


You will need to adjust the css a bit to have the input field aligned with the pagination buttons.

At least one thing to improve: store the present page number as initial value in the input field.

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>