Reputation: 31
I parse the json incoming data and transfer it to the table by append method. I open the new screen when I click on the table row, but I can not send the id value that I clicked.
that js
function fisYukle(dt) {
$('#tblFisList').empty();
$.each(dt, function (i, dt) {
$('#tblFisList').append("<tr onclick=fisAyrinti();return false;><td data-id=fis>" +
dt.ID + "</td><td>" +
dt.Evrakno + "</td><td>" +
dt.EvrakTarih + "</td><td>" +
dt.MagazaAd + "</td><td>" +
dt.Tutar + "</td></></tr>");
})
}
that's fisAyrinti() function
function fisAyrinti(data-id) {
$('#fisGizliID')[0].innerText = data-id;
$('#modal1').modal('open');
}
how to pass data-id to function (id in clicked row)? thanx
Upvotes: 0
Views: 980
Reputation: 6565
When you are appending the tr
you have not passed any argument to the function bound with it.
<tr onclick=fisAyrinti(this);return false;><td data-id=fis>
You can see that I have passed this
as an argument to the function, which will pass instance of the element. And inside the function you can take data-id
using
function fisAyrinti(tag) {
var data_id = $(tag).find('td:first').attr('data-id');
$('#fisGizliID')[0].innerText = data_id;
$('#modal1').modal('open');
}
Upvotes: 1
Reputation: 1456
Change fisAyrinti() to fisAyrinti(this) in your tr tag. And your function should be like:
function fisAyrinti(ctrl) {
var id = $(ctrl +' td:first-child').data('id');
}
Upvotes: 0