I have a table where some functions are triggered upon clicks on a link in each row:
The relevant part of the code is:
$('.my_table').inplacerowedit({
url: myurl,
});
in inplacerowedit.js file, I have:
(function($) {
$.fn.inplacerowedit = function(options) {
var ops = $.extend({}, $.fn.inplacerowedit.defaults, options);
$(this).find(ops.editbuttonselector).on('click', function(e) {
... }
ops.editbuttonselector = 'a.edit'
My table has an edit link each row and it's usually working fine. My problem is with new created rows.
Here is how I'm creating a row and adding it to the table:
new_row = null
getNewRow = function() {
if (new_row == null){
new_row = $("<tr>");
columns = {'name':'','type':'','value':'','edit':'','delete':''}
for (var column in columns)
new_row.append( $("<td>").addClass(column).text(columns[column]));
links = ['edit','delete']
for (var i=0;i<links.length;i++){
link = links[i]
a = $("<a href='"+link+"' class='"+link+"'>").text(link);
new_row.find("."+link).append(a)
}
}
return new_row
};
$("#addRowAndEdit").click(function(e){
e.preventDefault();
var row = getNewRow();
$(".my_table").append(row);
new_record = $('.my_table tbody>tr:last');
new_record.find('a.edit').click(); //this is the line that is not working.
....
}
UPDATE:
If I do new_record.find('a.edit').on('click', alert('ok'));
, the alert funcion works, but the other one is not called.
Any ideas? Thanks