0

I have these two columns in my table: effective_start_datetime and effective_end_datetime

1

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:

2

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:

3

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>';

4

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>`;

5

  • Use backticks (ie `\``) instead if single-quotes (ie `'`) around your `s_status` string – Phil Aug 16 '21 at 02:12
  • I am getting shift is not defined after using the backtick –  Aug 16 '21 at 02:17
  • 1
    That's simply a scoping problem. You would need to pass your `shift` object into the `getshiftstatus` function – Phil Aug 16 '21 at 02:42

0 Answers0