CGridView update does not render the div

Hi guys,

This seems to be an old problem, but I can’t find a clear solution.

What I need is:

The yii ajax that is used for CGridView sorting/filtering/paging, must not only update the gridview, but also the parent div containing the gridview (and other gridviews in the same div). This is not working, even if you render the whole form in the controller.

From the forums, it looks like the problem is with $(data).find(’#’+this) in jquery.yiigridview.js.

Does anybody know of a solution without changing the yii files?

Thanx

Hi there

Maybe I haven’t understood your problem or what you want to achieve, but if you want to run any JS code upon sorting/filtering/paging, you just use the afterAjaxUpdate property, like this:


<?php $this->widget('zii.widgets.grid.CGridView', array(

    'id' => 'some-grid',

    'dataProvider' => $model->search(),

    'filter' => $model,

    'afterAjaxUpdate'=>'js:function(id, data) { alert("Here you go…"); }',

    …

)); ?>

I have never tested, but I hope ‘ajaxUpdate’ property of CGridView may do what you want.

http://www.yiiframework.com/doc/api/1.1/CGridView/#ajaxUpdate-detail




    'ajaxUpdate' => 'grid-one-id, grid-two-id',



[s]Or




    'ajaxUpdate' => 'ancestor-div-id',



[/s]

[Updates]

OK. I’ve tested it myself.

The second one didn’t work.

I expected the 2 grids in the ancestor div to be updated, but not. The first grid disappeared. I don’t know why.

The first one worked.

But I didn’t have to list the id of its own.

Just the following was enough for grid-one.




    'ajaxUpdate' => 'grid-two-id',



Hi bennouna

afterAjaxUpdate could work to update the other gridviews in the div, but it would result in more round trips.

I want to pass all the gridview’s to the view in one round trip. It works during page refresh, but not during gridview sorting/filtering/paging because then only the gridview on which the sorting is performed gets refreshed.

So I want the whole page refreshed OR preferably the div containing the gridviews refreshed, when a gridview is sorted/filtered/paged.

softark, you are a champ.

‘ajaxUpdate’ => ‘grid-two-id’, works.

Thanx

Ok Gerhard, I understood your needs when I saw softark’s answer. He’s the best!