Sorry guys, I have a problem. how to get an id value from a column so i can use in url
Sorry guys, I have a problem. how to get an id value from a column so i can use in url
merchantguild
Posts: 5Questions: 2Answers: 0
in ColVis
var table = $('#relasiKeluarga').DataTable({
"ajax": "http://pintas_simulasi_3.test/api/relasi_keluargas",
"columns": [{
//defaultContent: '<input type="button" class="name" value="Name"/><input type="button" class="position" value="Position"/>'
},
{
"data": "id"
},
{
"data": "relasi_keluarga"
},
{
"data": "is_active"
}
],
"columnDefs": [{
"targets": [1],
"visible": false
},
{
"className": "dt-body-center",
"targets": [0],
"render": function(data, type, row, meta) {
return '<a class="btn btn-default btn-sm mx-2" href="http://url/{{ id }}"><i class="far fa-eye"></i></a>' +
'<a class="btn btn-default btn-sm" href="http://url/{{ id }}"><i class="far fa-edit"></i></a>';
},
}
],
});
$('#relasiKeluarga tbody').on('click', '.relasi_keluarga', function() {
var row = $(this).closest('tr');
var data = table.row(row).data().relasi_keluarga;
console.log(data);
});
$('#relasiKeluarga tbody').on('click', '.is_active', function() {
var row = $(this).closest('tr');
var data = table.row(row).data().is_active;
console.log(data);
});
This question has an accepted answers - jump to answer
Answers
You can use
cell().node()
to get the node, and then use jQuery'sattr
to get the ID from that node.Colin
mr collin and how to get an id on unvisible column id, and than passit to return button {{ id }} ... sorry my collin I'm new in programming world
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Read the
columns.render
docs. Therow
parameter has all the data for the row. Instead of"http://url/{{ id }}">
try"http://url/{{ row.id }}">
. If you still need help then post a test case as Colin requested.Kevin
@kthongren thanks for the answer sir, it really helped me...
@colin thanks for the directions sir