How to insert the ID of the JSON Response in the button of the last collum?
How to insert the ID of the JSON Response in the button of the last collum?
User123456
Posts: 57Questions: 15Answers: 0
I am doing server side activation, and I need to create 3 buttons in the last collum, simple CRUD buttons like this:
Usually their href
is for the trash deleteX.php?cod=ID and getSomething.php?cod=ID.
I alredy did them and they appear okay and fine in the last collum with pure jQuery:
$(document).ready(function() {
$('#companyTable').DataTable({
"processing": true,
"serverSide": true,
"ajax": "lib/server_processing.php",
"columns": [
{ "data": 0,
"render": function ( data, type, row ) {
var text = "";
if (type == "display") {
if (data == "1") {
text = "<i class='ace-icon fa fa-circle green'></i>";
} else {
text = "<i class='ace-icon fa fa-circle red'></i>";
}
data = text
}
return data;
},
},
{ "data": 1 },
{ "data": 2 },
{ "data": 3 },
{ "data": 4 },
{ "data": 5 },
{ "data": 6 }
],
"order": [ 1, "asc" ],
"columnDefs": [
{ "orderable": false, "targets": 0 },
{ "orderable": false, "targets": 7 },
{
"targets": 7,
"data": "",
"render": function(data, type, full){
return '<a data-toggle="modal" data-target="#infoModal" data-id="" id="getCompany" class="blue"><i class="ace-icon fa fa-search-plus bigger-130"></i></a> <a class="red" href="deleteCompany.php?id_Company="><i class="ace-icon fa fa-trash-o bigger-130"></i></a> <a class="orange" data-id="" id="blockCompany"><i class="ace-icon fa fa-eye-slash bigger-130"></i></a>';
}} ],
"sScrollX": "100%",
"sScrollXInner": "103%",
});
});
Howerever in a JSON like this:
["0", "FooBarBaz", "42.875.000/1486-83", "13630-275", "Rua Sofia Levi", "Aiur", "Vila Industrial", "4"]
How can I get the last position (in this case number "4" which is the ID), and put inside the button?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Use third argument
full
forcolumns.render
function to get access to full data for the row. Your id would be infull[7]
.For example:
See more articles about jQuery DataTables on gyrocode.com.
It's not working @gyrocode:
I think it's beacuse of the simple
'
. Do I need to escape these'
?You're right, I corrected the answer.
This is a very efficient forum, it's always helping me, thanks for the help.
@User123456, great username by the way , had a tough time selecting more meaningful one?
Yes, it was very hard for me to choose between, User1234, User12345 and User123456.