does somebody know a possibilty to set a default function in CGridView, which will run on all grids on the page after every AJAX update? I use the CGridView on many pages, and I don't want to specify this function for each grid separatly. I need this because I use jQuery selectmenu for my filter dropdowns, and after the AJAX reload, they need to be inicialized again.
'afterAjaxUpdate' => "function(id,data){$('select').selectmenu()}";
See the format of value http://www.yiiframework.com/doc/api/1.1/CGridView#afterAjaxUpdate-detail
a javascript function that will be invoked after a successful AJAX response is received. The function signature is function(id, data) where 'id' refers to the ID of the grid view, 'data' the received ajax response data.
You need set
'afterAjaxUpdate' => "function(id,data){$('select').selectmenu()}";
UPDATED:
I don't see another way than create child of CGridView
and set value of $afterAjaxUpdate
. Here is the code:
class GridView extends CGridView{ public $afterAjaxUpdate = "function(id,data){$('select').selectmenu()}"; }
UPDATED:
I look at the source code of widget and the property afterAjaxUpdate
used only in the method registerClientScript
. That's why I propose anothe two solution. First - you may change value of afterAjaxUpdate
in init of inherited class:
public function init(){ parent::init(); // after setting all values reset value to desire $this->afterAjaxUpdate = "function(id,data){$('select').selectmenu()}"; }
Second - you can rechange it propery before calling method registerClientScript
:
public function registerClientScript(){ $this->afterAjaxUpdate = "function(id,data){$('select').selectmenu()}"; parent::registerClientScript(); }