Display expired based on the date

Display expired based on the date

Alex2019Alex2019 Posts: 48Questions: 9Answers: 0

Hello everyone,
How do I see a expired label based on the scadenza field?

Example: scadenza
2021-08-31 expired (in red)

code

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',
                    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() {

Replies

  • colincolin Posts: 12,986Questions: 0Answers: 2,214
    edited September 19

    I'm not clear what you're asking. If you want the date to change to a text string "expired", then you would use columns.render, as you are with the buttons in the final column.

    Colin

  • Alex2019Alex2019 Posts: 48Questions: 9Answers: 0
    edited September 18

    Hi Colin,
    If the date has expired, I would like to view a label (or badge) near the date with the word "Expired"
    could you post an example adapted with my code? I don't know how to do it

  • kthorngrenkthorngren Posts: 14,210Questions: 25Answers: 3,357
    edited September 18

    See if this example will get you started. Look at moment.js for you date comparison.

    Kevin

  • Alex2019Alex2019 Posts: 48Questions: 9Answers: 0

    Hi kthorngren,
    The problem is not very experienced (I am not a programmer), :/
    the code found it on the net and adapted
    Could you kindly provide me with an example based on my code? :|
    best in (live.datatables.net/)

Sign In or Register to comment.