Cgridview Update() Data Issue


I have a CGridView with a custom CDataColumn extension. In my CDataColumn I render a link based on a boolean flag on my model. Depending on the boolean value, the column will either display "Yes" or "No" and generate an ajax link to toggle the model value in the database, then update the CGridView using update().

This works perfectly upon the first toggle - when the user clicks the Yes or No link for the first time; the model value is updated in the database and the CGridView is refreshed, and my CDataColumn displays the new link. However, it seems that although the CGridView HTML is updated, the ajax javascript associated with my CDataColumn is not refreshed. This means that the ajax Yes/No link generated and the model value is not changed in the ajax data parameters. When the user clicks the link for the second time, the model value sent in the ajax post is the old, wrong value.

I hope I’ve explained the problem clearly enough. In summary, model attribute values associated with ajax calls are not refreshed when update() is called on CGridView. What’s going on here?

Thanks in advance.


Hi can you try the generate the random id pass on ajax link



for ex…

 echo CHtml::ajaxlink('Request New Liquor', array('liquor/addnewliquor'), array(

            	"type" => "GET",

            	"data" => array("vid" => $vid, "ajax" => true),

            	"success" => "function(data){



                	), array('live' => false, 'class' => 'blue', 'id' => rand(0, 99999)));

As you noticed, CGridView does not refresh the script.

I suggest you not to use ajax link but write the code directly in js.

You can create the link as "standard" link and delegate a function which call the same url as an ajax request and refresh the grid like:

$('body').delegate('.mylinkClass', 'click', function(e){



      url: $(this).attr('href'),

      success: function(){ $('#my-grid').yiiGridView('update')}




Thanks for the replies guys.

The solution I went with was calling a toggleFlag() method on my model through the controller action, thus eliminating the need to refresh the value in the CGridView script.