add new row and set img click event on one column of newly created row

add new row and set img click event on one column of newly created row

manoharsolanki123manoharsolanki123 Posts: 8Questions: 0Answers: 0
edited September 2010 in General
Hi Allan,
I need to add a new row to a datatable which I have achieved using fnAddData()
Now on this row I have a image which on clicked supposed to opens a dialog box.
I have this click function working for existing rows, but when a new row is added this click event is not working.
Not sure but I suppose its a post initialisation event, so I saw the tooltip eg on your site.
But my confusion is that what do I use $( oTable.fnGetNodes() ).XXXXX here
Thanks in advance
code is below:
[code]
$(document).ready(function() {
oTable = $('#addModifySuppTbl').dataTable();

$('#add').click( function() {
$('#addModifySuppTbl').dataTable().fnAddData( [
"",
"",
"",
"",
"",
""
],true );

giCount++;
});


$('td img', oTable.fnGetNodes() ).each( function () {

$(this).click( function () {
var rowIndex = this.parentNode.parentNode.rowIndex;
/* Get the position of the current data from the node */
var aPos = $('#addModifySuppTbl').dataTable().fnGetPosition( this );
//Opens a dialog for that row
$('#searchDialog').data("rowIndex",rowIndex).dialog('open');

} );

} );

});

[/code]
regards,
Manohar

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Try using live events. $('td img').live( 'click', function() { ... } ); instead.

    Allan
  • manoharsolanki123manoharsolanki123 Posts: 8Questions: 0Answers: 0
    Thanks Allan for this prompt response.
    It does worked.

    Regards,
    Manohar
  • whut_raywhut_ray Posts: 1Questions: 0Answers: 0
    edited May 2012
    Thanks,
    It solves me the same question

    Ray
This discussion has been closed.