What's the best way to perform ajax on a table cell?

What’s the best method to implement ajax on a table cell? What I’d like to do is convert the table column to hyperlinks using CLinkColumn and onclick of a cell link run a calculation, submit the calculated value to the database and replace the cell link value with the updated value from the database.

I figured the best way to do it was to use CHtml::ajaxLink and then add the parameter array(‘update’ => ‘#id’) on success. However the table cell ids will be dynamic. How can I update the cell contents using JQuery with dynamic ids? Same issue if I use custom jQuery.


[font="Courier New"]$(this)[/font] will select your link, so [font="Courier New"]$(this).parent()[/font] will select the parent cell, and [font="Courier New"]$(this).parent().parent()[/font] the row.

What I’d do is set a class to the columns you want to access, so that I can use [font=“Courier New”]$(this).parent().parent().children(’.theClassName’)[/font] to access the cell (with theClassName class) in the same row

Edit: added a dot in the children() method’s selector because since it’s a class name

By the way, as far as I know, ‘update’ is an interesting property for divs and spans, ie DOM elements with html(). For table cells, you’ll rather want to use the ‘success’ property and [font=“Courier New”]text()[/font] method, ie

array('success' => 'js:function(data){$(this).parent().parent().children(".theClassName").text(data);}'

PS There was a typo in the first post, corrected