I have these two columns in my table: effective_start_datetime
and effective_end_datetime
In my function I am trying to do an if condition for three situations:
Inactive
if effective_start_datetime
is null, Active
if effective_end_datetime
is null, else show a custom date without the time (e.g. From: 2021-08-23 To: 2021-08-25
)
UI:
Code Snippet: (I used shift.
to get the column data from the table)
<td>${getshiftstatus(shift.effective_start_datetime, shift.effective_end_datetime)}</td>
function getshiftstatus(start_datetime, end_datetime) {
var s_status = '';
if (start_datetime === null) {
s_status = '<p class="text-danger">Inactive</p>';
} else if (end_datetime === null) {
s_status = '<p class="text-success">Active</p>';
} else {
s_status = '<p>Custom</p>';
}
return s_status; }
I am trying to change s_status = '<p>Custom</p>';
into a custom date like:
s_status = '<table><tr class="row-gray"><td class="p-0 font-weight-bold">From:</td><td class="tb-schedule">2021-08-23</td></tr><tr class="row-gray"><td class="p-0 font-weight-bold">To:</td><td class="tb-schedule">2021-08-25</td></tr></table>';
The code above gives me:
But when I tried to add the variables I am getting a string instead of the SQL data:
s_status = '<table><tr class="row-gray"><td class="p-0 font-weight-bold">From:</td><td class="tb-schedule">${shift.effective_start_datetime}</td></tr><tr class="row-gray"><td class="p-0 font-weight-bold">To:</td><td class="tb-schedule">${shift.effective_end_datetime}</td></tr></table>';
How do I get my SQL shift.
data in my function variable?
UPDATE:
I am getting shift is not defined
after using a backtick. It seems like my shift.
is not getting read inside my function
s_status = `<table><tr class="row-gray"><td class="p-0 font-weight-bold">From:</td><td class="tb-schedule">${shift.effective_start_datetime}</td></tr><tr class="row-gray"><td class="p-0 font-weight-bold">To:</td><td class="tb-schedule">${shift.effective_end_datetime}</td></tr></table>`;