I would like to display the word "Today" instead of, for example, "Mon 16 Aug 2021" in my Datatable.js table.
See fiddle here: https://jsfiddle.net/mauricetwomey/nsbk7Lry/62/
I would like the result to display "Today" wherever today's date is in the table:
I am using moment.js to handle the date formatting but I cannot get the locale feature to automatically change a date format to a string.
$(document).ready( function () {
$.fn.dataTable.moment('ddd D MMM YYYY');
var table = $("#orders").DataTable({
columns: [
{ orderable: !1 },
{ orderable: !0 },
{ orderable: !1 },
{ orderable: !1 },
{ orderable: !1 },
],
order: [[1, "desc"]],
});
});
You could do this using createdCell
"columnDefs": [{
"targets": [1,3],
"createdCell": function(td, cellData, rowData, row, col) {
if (moment(cellData).isSame(moment(), "day")) {
$(td).html('Today')
}
}
}]