jquery - Creation of a big table with edit button for each record -
i have big html table generated this:
function getspeciesrowhtml(row_data) { var html = ""; html = html + '<tr>' + '<td>' + row_data.id + '<input type="hidden" class="species_table_ids" value="' + row_data.id + '"></td>' + '<td>' + row_data.name + '</td>' + '<td>' + row_data.name_lat + '</td>' + '<td>' + row_data.class + '</td>' + '<td>' + row_data.family + '</td>' + '<td>' + row_data.family_lat + '</td>' + '<td>' + row_data.order + '</td>' + '<td>' + row_data.order_lat + '</td>' + '<td>' + row_data.spec_status + '</td>' + '<td><a class="btn_species_delete">edit</a></td>' + //delete button '</tr>' ; return html; } function filltable(data) { var html = ""; $.each(data, function (i, item) { html = html + getspeciesrowhtml(data[i],true); }); $('#species_table tbody') .prepend($(html)); }; data table comes database through controller. fact data can deleted. purpose in each row of table there button "delete". delete buttons initialized class selector because them (a line line table creation takes monstrous amount of time):
$('.btn_species_delete') .button({ icons: { primary: "ui-icon-trash" }, text: false }) .click(function () { deletespecies(id); }); that is, when press "delete" function must called should referred "id" property. problem each button has own unique "id" , have not idea how transfer there. because initialization of buttons performed through whole class. how best handle this, work possible?
add data attribute <a>, example
'<a class="btn_species_delete" data-rowid="'+row_data.id+'">' then in onclick:
deletespecies($(this).attr('data-rowid'));
Comments
Post a Comment