Yii Framework Forum: Very Easy 'jump To Page' Addition To Cgridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Very Easy 'jump To Page' Addition To Cgridview pager jump cgridview Rate Topic: -----

#1 User is offline   Binc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 11-January 12

Posted 22 October 2012 - 05:41 AM

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.
0

#2 User is offline   Binc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 11-January 12

Posted 23 October 2012 - 05:21 AM

It is too 'dirty' to do it like this after all.

I recommend to use the 'mypager' extension. Very easy to implement.
http://www.yiiframew...ension/mypager/
0

#3 User is offline   qingyue 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 18-September 09

Posted 30 July 2013 - 02:21 AM

View PostBinc, on 22 October 2012 - 05:41 AM, said:

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.


very very good!

this codes
ucfirst(Yii::app()->controller->id)
replace with
get_class($model)
is better may be.
agree with me ?
0

#4 User is offline   qingyue 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 18-September 09

Posted 30 July 2013 - 03:04 AM

View PostBinc, on 22 October 2012 - 05:41 AM, said:

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.


if put the input in GridView, it can jump to page only first time. why and how to solve ? Thanks.

'template' => '{items}'.CHtml::textField(ucfirst(Yii::app()->controller->id)."_page",'',array('id'=>'jump-to-page')).'<input type="button" id="jumptopage" value="Go">{pager}{summary}',

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users