ho provato cosi, ma niente, non funziona
in index.php e' anche presente il link a bootstrap
Codice HTML:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
Codice PHP:
columnDefs: [
{
render: function(data, type, row) {
console.log()
if (strtotime(row.date_to) < strtotime(date("Y-m-d"))) {
return '<span class="label label-success">Active</span>';
}
else if (strtotime(row.date_to) > strtotime(date("Y-m-d"))) {
return 'span class="label label-warning">Expired</span>';
}
else {
return '<span class="label label-default">Deactive</span>';
}
}, targets: [5]
}
],
script.js
Codice PHP:
var authorsTbl = '';
$(function() {
// draw function [called if the database updates]
function draw_data() {
if ($.fn.dataTable.isDataTable('#authors-tbl') && authorsTbl != '') {
authorsTbl.draw(true)
} else {
load_data();
}
}
function load_data() {
authorsTbl = $('#authors-tbl').DataTable({
dom: '<"row"B>flr<"py-2 my-2"t>ip',
"processing": true,
"serverSide": true,
"ajax": {
url: "./get_authors.php",
method: 'POST'
},
columns: [{
data: 'id',
className: 'py-0 px-1'
},
{
data: 'nome_farmaco',
className: 'py-0 px-1'
},
{
data: 'principio_attivo',
className: 'py-0 px-1'
},
{
data: 'posologia',
className: 'py-0 px-1'
},
{
data: 'confezionato',
className: 'py-0 px-1'
},
{
data: 'scadenza',
className: 'py-0 px-1'
},
{
data: null,
orderable: false,
className: 'text-center py-0 px-1',
columnDefs: [
{
render: function(data, type, row) {
console.log()
if (strtotime(row.date_to) < strtotime(date("Y-m-d"))) {
return '<span class="label label-success">Active</span>';
}
else if (strtotime(row.date_to) > strtotime(date("Y-m-d"))) {
return 'span class="label label-warning">Expired</span>';
}
else {
return '<span class="label label-default">Deactive</span>';
}
}, targets: [5]
}
],
render: function(data, type, row, meta) {
console.log()
return '<a class="me-2 btn btn-sm rounded-0 py-0 edit_data btn-primary" href="javascript:void(0)" data-id="' + (row.id) + '">Edit</a><a class="btn btn-sm rounded-0 py-0 delete_data btn-danger" href="javascript:void(0)" data-id="' + (row.id) + '">Delete</a>';
}
}
],
drawCallback: function(settings) {
$('.edit_data').click(function() {