Cgridview Afterajaxupdate Problem


I have a form in CGridView and implement ajax for submitting the form:

In my view:



  function ajaxApproveItem()


    $(".approve-item").submit(function() {

      frm = $(this);

      frm.append('<input type="hidden" name="ajax" value="1">');

      $.post(frm.attr('action'), frm.serialize(),

        function(result) {

          if (result.code==1) {


          } else {




      , "json");

      return false;




, CClientScript::POS_HEAD);

$this->widget('bootstrap.widgets.TbGridView', array(



        'afterAjaxUpdate' => 'ajaxApproveItem()',







           'value'=> function($data, $row) {

              return '<form class="approve-item" action="'.Yii::app()->createUrl("item/approveitem").'" method="POST">

                     <input type="hidden" name="id" value="'.$data->id.'" />

                     <input type="hidden" name="token" value="'.app()->request->getCsrfToken().'" />

                     <input type="image" src="'.Yii::app()->request->baseUrl.'/images/update.png'.'" />




The problem is, it works at initial run ( when I submit the form, the ajax runs perfectly and the grid is refreshed by calling $(’#data-grid’).yiiGridView(‘update’) ), but after that the ajax doesn’t work anymore (when I submit the form, it is submitted like no ajax event bound).

Could someone help me? Thanks.

i think you can write something look like this




It doesn’t work either…

ok so best way you can call a onclick function on update’s so easy and it’s work perfectly.

At last I make it working… the problem is I need to write it like this:

  'afterAjaxUpdate' => 'ajaxApproveItem',  // without () at the end

and then I need to make initial call to the function at document ready state:




Damn…took the whole day to figure it out, had tried many possibilites and none was working… I guess it needs to be more clear in the documentation…