Yii CGridView - 设置默认的afterAjaxUpdate回调

Asp*_*ped 0 php ajax yii select-menu cgridview

有人知道在CGridView中设置默认函数的可能性,它会在每次AJAX更新后在页面上的所有网格上运行吗?我在许多页面上使用CGridView,我不想分别为每个网格指定这个函数.我需要这个,因为我使用jQuery selectmenu作为我的过滤器下拉列表,并且在AJAX重新加载之后,它们需要再次被初始化.

'afterAjaxUpdate' => "function(id,data){$('select').selectmenu()}";
Run Code Online (Sandbox Code Playgroud)

Cre*_*toR 6

请参阅值的格式http://www.yiiframework.com/doc/api/1.1/CGridView#afterAjaxUpdate-detail

收到成功的AJAX响应后将调用的javascript函数.函数签名是函数(id,data),其中'id'是指网格视图的ID,'data'是接收到的ajax响应数据.

你需要设定

'afterAjaxUpdate' => "function(id,data){$('select').selectmenu()}";
Run Code Online (Sandbox Code Playgroud)

更新:

我没有看到另一种方式,而不是创建子的CGridView和设置值$afterAjaxUpdate.这是代码:

class GridView extends CGridView{
    public $afterAjaxUpdate = "function(id,data){$('select').selectmenu()}";
}
Run Code Online (Sandbox Code Playgroud)

更新:

我查看了widget的源代码和afterAjaxUpdate仅在方法中使用的属性registerClientScript.这就是我提出另外一个解决方案的原因.首先 - 您可以更改afterAjaxUpdate继承类的init中的值:

public function init(){
    parent::init(); // after setting all values reset value to desire
    $this->afterAjaxUpdate = "function(id,data){$('select').selectmenu()}";
  }
Run Code Online (Sandbox Code Playgroud)

第二 - 你可以在调用方法之前重新改变它registerClientScript:

public function registerClientScript(){
    $this->afterAjaxUpdate = "function(id,data){$('select').selectmenu()}";
    parent::registerClientScript();
  }
Run Code Online (Sandbox Code Playgroud)