Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii CGridView javascript event on pagination

Tags:

javascript

yii

I am extending CGridView in Yii using jQuery to remember the checked rows when switching pages. The pages are loaded using AJAX, so i thought that when the request is finished and the new page is rendered, i want my code to step in an do it's magic. However, i can't seem to find any documentation that indicates any event being fired or so when the new page is finished rendering.

I could however use DOM listeners but i figured it would be better to use one event for the whole page.

like image 320
Anton Gildebrand Avatar asked Feb 12 '13 17:02

Anton Gildebrand


1 Answers

You can use afterAjaxUpdate (since your pages are loaded with ajax):

$this->widget('zii.widgets.grid.CGridView', array(
    // ... options ...
    'ajaxUpdate'=>true,
    'afterAjaxUpdate'=>'aFunctionThatWillBeCalled', //
    // ... more options ...
));

You can add the js function like so:

Yii::app()->clientScript->registerScript('some-script-id','function aFunctionThatWillBeCalled(id, data){
    console.log("id is "+id);
    // your jquery code to remember checked rows
}');
like image 99
bool.dev Avatar answered Oct 23 '22 17:10

bool.dev