Tuesday, 15 July 2014

datatables - pass $(this) in JQuery on event for deleting a row in a table -



datatables - pass $(this) in JQuery on event for deleting a row in a table -

i have next html code represents part of table

<tr> <td> <span class='tip'><a href='#' class='delete' data-name='product1' title='delete'><img src='images/icon/icon_delete.png'></a></span>" </td> </tr> <tr> <td> <span class='tip'><a href='#' class='delete' data-name='product2' title='delete'><img src='images/icon/icon_delete.png'></a></span>" </td> </tr>

and js

$(document).on('click', '.delete', function () { var name = $(this).attr("data-name"); $.confirm({ 'title': 'delete row', 'message': "<strong>do want delete </strong><br /><font color=red>' " + name + " ' </font> ", 'buttons': { 'yes': { 'class': 'special', 'action': function () { // problem // trying row var row = $(this).closest("tr").get(0); otable.fndeleterow(row); } }, 'no': { 'class': '' } } }); });

i trying row id able delete it. how can pass caller click event

edit: trying delete row, maybe there other ways

your problem within $.confirm plugin's action callback function, value of this else (i.e. not dom node). save reference $(this) before calling plugin, , utilize reference within action callback. like:

$(document).on('click', '.delete', function () { var node = $(this); var name = node.attr("data-name"); $.confirm({ 'title': 'delete row', 'message': "<strong>do want delete </strong><br /><font color=red>' " + name + " ' </font> ", 'buttons': { 'yes': { 'class': 'special', 'action': function () { var row = node.closest("tr").get(0); otable.fndeleterow(row); } }, 'no': { 'class': '' } } }); });

this bit of guess, since i'm not farmilar confirm plugin, it's mutual js pitfall.

jquery datatables

No comments:

Post a Comment