[SOLVED] REinit javascript?

Hello.

I’m just working on a active DropDown List (with class=‘EDropDownColumn’) inside CGridView column.

It displays a list of statuses and on change sends an ajax request to a controller which updates the model in database.

Works like a charm, but only for first page of the grid. Or only once, because I call $.fn.yiiGridView.update. So when the grid is updated because of filter, sorting, pagination or my custom call, the whole thing stops working.

This is the javascript that does the ajax execution.


Yii::app()->clientScript -> registerScript('EDropDownColumnJS', 

"$('.EDropDownColumn').change(function() 

 {

   $.ajax({

    type: 'POST',

    url: '<link_to_controller>',

    data: ({code: this.getAttribute('id'), status: this.options[this.selectedIndex].value, ajax: true}),

    success: function(msg)

    {

     if (msg == 'OK')

      $.fn.yiiGridView.update('<grid_id>');

    }

   });

  }

);", 

CClientScript::POS_LOAD);

What I suspect is, that when the whole grid DIV is replaced by javascript, the DOM elements are not the same any more, although they have the same ID. So the $(’.EDropDownColumn’).change selector doesn’t find the elements (which were referenced on CClientScript::POS_LOAD).

If this is the case, is there a way to rerun/reinit the "EDropDownColumnJS" clientScript after the grid update event?

Thanks for the help and have a nice day.

Solved it. Typical, 3 minutes after posting the question…

I replaced $(’.EDropDownColumn’).change(function() {…}) with $(’.EDropDownColumn’).live(‘change’, function(…))

You have to love jQuery. .)