Yii Framework Forum: Help add field to change pageSize in CgridView - Yii Framework Forum

Jump to content

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

Help add field to change pageSize in CgridView Rate Topic: -----

#1 User is offline   fhelix72 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 22-April 09
  • Location:Italy - Vicenza

Posted 16 April 2010 - 11:35 AM

I would like to add to ClinkPager a text field (at the end of the pages buttons) where user can change the pageSize property (the number of rows for page).

First I try with a normal grid (created manually, so not using CGridView), I created a MyLinkPager.php where I override the CLinkPager "run" function by adding at the end a textField (Id="rowPages") with a link button "GO" that if pressed resubmit the form, then in the controller action "List" I check if $_POST['rowPages'] is set and I change the pageSize property of MyLinkPager. This functions perfectly.

Now I want it to function in CGridView in Ajax mode, but I'm not able.
First i specified in the CGridView to use 'pager'=>'myLinkPager', then, as previously done, in myLinkPager at the end of "run" function I used a textField ('rowPages') and a "GO" link with ajax parameters for POST the textField value to the current URL and refresh the grid, but this doesn't function, after insert a number in the textField and press the GO button nothing happens. This is the code I added at the end of the overrided "run" function:

echo CHtml::TextField('rowPages', $this->pageSize, array('size'=>'1', 'maxlength'=>'8', 'class'=>'yiiPager')); 
echo CHtml::link('GO', $this->createPageUrl($this->getCurrentPage()), array('id'=>'rowPagesButton', 'class'=>'yiiPager', 'ajax'=>array('type'=>'POST', 'data'=>'#rowPages', 'url' => $this->createPageUrl($this->getCurrentPage())))); 

I think the problem is in Ajax parameters, I tried to eliminate them and now after pressing the GO link the grid is refreshed but it doesn't change the pageSize (because obviously is not posted to the URL, but how can I post correctly the "rowPages" value with Ajax?)
I tried also with an ajaxLink but with any result.
Thanks for helping me.
0

#2 User is offline   fhelix72 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 22-April 09
  • Location:Italy - Vicenza

Posted 20 April 2010 - 05:22 AM

Anyone can help me?
0

#3 User is offline   fhelix72 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 22-April 09
  • Location:Italy - Vicenza

Posted 20 April 2010 - 09:11 AM

As I didn't receive any reply I find a solution by myself, so I didn't pass the rowPages in POST because I wasn't able this solution to function, but I pass the value in $_GET by changing dinamically the href of the link button so this is the code I used:

echo CHtml::TextField('rowPages', $this->pageSize, array('size'=>'1', 'maxlength'=>'8', 'class'=>'yiiPager')); 
echo CHtml::link('GO', $this->createPageUrl($this->getCurrentPage()), array('id'=>'rowPagesButton', 'class'=>'yiiPager', 
    , 'onclick'=>'current_Url=window.location.search;
                  new_Url=current_Url.replace(/&rowPages([\S])+/g,"");
                  document.getElementById("rowPagesButton").href = new_Url + "&rowPages=" + document.getElementById("rowPages").value;' 
)); 


Before using Javascript I tried also with Jquery code (in click function) but it function just the first time, I don't know why so a the end I used javascript.
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