Yii Framework Forum: How To Refresh Cgridview? - Yii Framework Forum

Jump to content

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

How To Refresh Cgridview? Rate Topic: -----

#1 User is offline   Jorgee 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 58
  • Joined: 22-March 13

Posted 16 May 2013 - 04:01 PM

Hi, I have a CGridView and I'd like to put a button to refresh.

I've tried adding AjaxButton but I couldn't make it.

The grid ID is session-grid.

I have a partial view with only the CGridView.

I managed to get it working but it's duplicated, I am missing anything?

Thanks a lot!
0

#2 User is offline   Fabrizio Caldarelli 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 977
  • Joined: 21-March 13
  • Location:Rome, Italy

Posted 16 May 2013 - 04:19 PM

$.fn.yiiGridView.update("session-grid")

Yii2 by example: my book about Yii2
https://www.packtpub...nt/yii2-example
0

#3 User is offline   sefburhan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 148
  • Joined: 08-February 12
  • Location:islamabad

Posted 17 May 2013 - 01:49 AM

View PostJorgee, on 16 May 2013 - 04:01 PM, said:

Hi, I have a CGridView and I'd like to put a button to refresh.

I've tried adding AjaxButton but I couldn't make it.

The grid ID is session-grid.

I have a partial view with only the CGridView.

I managed to get it working but it's duplicated, I am missing anything?

Thanks a lot!


try this
Yii::app()->clientScript->registerScript('session', "

$('#buttonID').click(function(){
$.fn.yiiGridView.update('session-grid', {
data: $(this).serialize()
});
return false;
});
");
0

#4 User is offline   Jorgee 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 58
  • Joined: 22-March 13

Posted 17 May 2013 - 07:26 AM

Thanks, but can't I just use CHTML::AjaxButton with parameters?

Edit: Seems that finally I managed to get it working.
<?php 
  $this->widget('bootstrap.widgets.TbButton', array(
    'label'=>'Actualizar',
    'buttonType'=>'ajaxButton',
    'type'=>'primary',
    'url'=>array('productSession/admin','ajax'=>'session-grid'),
    'ajaxOptions'=>array(
      'replace'=>'#session-grid',
    ),
    'htmlOptions'=>array(
      'id'=>'updateGrid',
    )
  )); 
?>


Does the magic, but without the 'loading' image.

Strange is that if I put 'update' instead of 'replace', when I click the Delete button in the grid, I get a JavaScript error regarding to url not defined.
0

#5 User is offline   Jorgee 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 58
  • Joined: 22-March 13

Posted 17 May 2013 - 10:00 AM

Well I finally opted for another solution:

<?php 
Yii::app()->clientScript->registerScript('initRefresh',<<<JS
    $('#update-grid-button').on('click',function(e) {
        e.preventDefault();
        $('#session-grid').yiiGridView('update');
    });
JS
,CClientScript::POS_READY);

  $this->widget('bootstrap.widgets.TbButton', array(
    'label'=>'Actualizar',
    'type'=>'primary',
    'icon'=>'repeat white',
    'htmlOptions'=>array(
      'id'=>'update-grid-button',
      'class'=>'pull-right',
    )
  )); 
?>

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