【问题标题】:Implement refresh button in Yii for a CGridView在 Yii 中为 CGridView 实现刷新按钮
【发布时间】:2013-05-16 21:03:05
【问题描述】:

我有一个 CGridView,我想放一个按钮来刷新。

我已经尝试添加 AjaxButton,但无法成功。

网格 ID 是 session-grid。

我有一个只有 CGridView 的局部视图。

我设法让它工作,但它被复制了,原来的保留在那里。我错过了什么?

非常感谢!

编辑:选择:

<?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',
    )
  )); 
?>

【问题讨论】:

  • 分享到现在你做了什么?

标签: yii cgridview


【解决方案1】:
<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); ?>

【讨论】:

  • 谢谢,我不能只使用带参数的 CHTML::AjaxButton 吗?
  • 您不能使用 AJAX 按钮。 Yii 的 GridView 会为你执行 AJAX 请求。
  • 谢谢,我可以使用yiiframework.com/forum/index.php/topic/… 按钮,但因为我只需要设置 ajax 选项,所以我不喜欢它。我更喜欢你注册 JS 的解决方案,这样我就可以管理其他 JQuery 东西,比如 ajaxStart()。
【解决方案2】:

您可以使用$.fn.yiiGridView.update('session-grid');

例子:

$("#my_button" ).click(function() {
    $.fn.yiiGridView.update('session-grid');
});

【讨论】:

  • 这也会重置过滤器和分页。
【解决方案3】:
function update(mygrid)
{
   var $form = $("<form action=\"\" data-pjax></form>").appendTo($(mygrid));
   $form.submit();
}

【讨论】:

  • 虽然这段代码 sn-p 可以解决问题,但including an explanation 确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
猜你喜欢
  • 1970-01-01
  • 2014-06-15
  • 1970-01-01
  • 1970-01-01
  • 2011-03-05
  • 2014-02-18
  • 1970-01-01
  • 2013-09-15
  • 1970-01-01
相关资源
最近更新 更多