Question

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, the original stays there. I am missing anything?

Thanks a lot!

EDIT: Chosen:

<?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',
    )
  )); 
?>
Était-ce utile?

La solution

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

Autres conseils

You can use $.fn.yiiGridView.update('session-grid');

Example:

$("#my_button" ).click(function() {
    $.fn.yiiGridView.update('session-grid');
});
function update(mygrid)
{
   var $form = $("<form action=\"\" data-pjax></form>").appendTo($(mygrid));
   $form.submit();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top