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_ohio
Posts: 1Questions: 1Answers: 0
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
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
andcolumns.render
fromcolumnDefs
intocolumns
to have the single object.Colin
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