[Solved]Error Ajax Call Into Dependent Cgridview


I have 2 CGridViews into a view:

1- Unassigned cars.

2- Assigned cars.

Unassigned cars grid have this button:



               'assignCar'=> array(

                   'label' => '<span class="glyphicon glyphicon-chevron-left"></span>',



                               'title' => 'Asign Car',




                                        'success' => 'function (data)


                                                        // If there were no errors









This works correctly. Unassigned car happens to be assigned and both grids update correctly, and current page in the web browser doesn’t change.

Assigned car grid have the same button (called "unassignCar"), but with:


This works correctly too, but page displayed in the web browser is "Yii::app()->createUrl(controller/unassigCar")" and not the current page.

Someone can help me?


Just to point this out - there is double quote missing inside the brackets ‘url’=>‘Yii::app()->createUrl(controller/unassignCar")’,

Good morning!

I was wrong for writing the code in the message, but it is fine in the application.

More ideas?

I know the problem is that the assigned car grid update when I click on the unassigned car grid.

The first time the page loads, if I fill assigned cars grid with static data and unassign a car, the page displayed in web browser doesn’t change.

Why update the unassigned cars is done correctly but the assigned cars grid loses its AJAX?

If I do “beforeSend” in the button of assigned cars grid, it doesn’t work, but it works if I put static data.


I got it.

When Yii renders my unassigned cars grid, it writes something like that for each element:


   jQuery.ajax({'type':'POST','url':$(this).attr('href'),'success':function (data)


      // Do domething.


},'cache':false,'data':jQuery(this).parents("form").serialize()});return false;});

But only for existing elements!!!!!! Then, as my assigned car list is empty, Yii doens’t write the above code for its elements.

My CGridViews have 10 elements at most. Then, if unassigned cars grid has 10 elements, when I assign a car, the new assigned car element hasn’t the above code.

We have to write it manually.

Then, I add this code:


    var itemCount = <?php 

                         echo (int)$model->search()->getTotalItemCount(); 


    var index= 10; 

    itemCount = parseInt(itemCount );    


    if(itemCount < 10)                           

        index= itemCount ;


    for(i=index; i<19; i++)


        jQuery('body').on('click','#yt' + i,






                                        'success':function (data)








                            return false;





This add AJAX behavior for items in need. At first, assigned cars will be empty, then, I have to write this code 20 (2 grids, 10 elements per page) - itemCountUnassignedCarsGrid times.