Show button for row if date in another column is within the last 30 days.

Show button for row if date in another column is within the last 30 days.

msmith_ohiomsmith_ohio Posts: 1Questions: 1Answers: 0
edited April 11 in Free community support

I have a five column table with a date in my second column and an edit button in my fifth column that the value of the edit button is from the json. I would like the edit button to only appear if the date in the second column is within the last 30 days. I believe I need to use rowcallback, however I can't figure it out.

columnDefs: [
    {
        targets: 5,
        orderable: false,
    
    render: function (data, type, row, meta) {
            return '<a class="button" data-url="/record/' + data + '/comment/">edit</a>'
        }
    }
],
columns: [
    { data: 'name' },
    { data: 'location' },
    { data: 'date' },
    { data: 'hours' },
    { data: 'floor' },
    { data: 'id' }
],

Answers

  • colincolin Posts: 15,158Questions: 1Answers: 2,587

    With the render function, you have the data for the row in row, so you can just return something different based on the date.

    Btw, you can just move the columns.orderable and columns.render from columnDefs into columns to have the single object.

    Colin

  • allanallan Posts: 61,787Questions: 1Answers: 10,115 Site admin

    Also, use Luxon or Moment.js to do the date calculation. You could do it manually, particularly if you are using ISO8601 formatted dates, but a library can make it a bit easier.

    Allan

Sign In or Register to comment.