jeudi 15 juillet 2021

Laravel/Ajax: highlight color inactive or active inside a function

If you will see at the code below, under my success: function (response), getgroupstatus will show either active or inactive depending on the row column.

1

        function fetchgroup() {
            $.ajax({
                type: "GET",
                url: "/clinical/bbr-group-configuration-group-list",
                dataType: "json",
                success: function (response){
                    var tbody="";
                    $.each(response.all_groups, function (key, group) {
                    tbody+=`
                        <tr>
                            <td><p class="font-weight-bold mb-0">${group.group_name}</p>${group.group_description}</td>
                            <td>${group.group_type_name}</td>
                            <td>User List</td>
                            <td>${getgroupstatus(group.effective_start_datetime)}</td>
                            <td>
                                <button type="button" value="${group.group_id}" class="edit_group btn btn-outline-secondary"><i class="fas fa-edit"></i> Edit</button>
                                <button type="button" value="${group.group_id}" class="delete_group btn btn-outline-secondary"><i class="fas fa-trash"></i> Delete</button>
                            </td>
                        </tr>`;
                    });
                    
                    $('#main-group-list tbody').html(tbody)

                    //condition if status is shown as active or inactive
                    function getgroupstatus(status) {
                        var g_status = '';
                        if (status === null) {
                            g_status = 'Inactive'
                        } else {
                            g_status = 'Active'
                        } 
                        return g_status;
                    }
                }
            });
        }

This page of mine already has bootstrap so I am trying to have the active text-success and the inactive text-danger.

My problem is that I need to target the <td> outside the getgroupstatus to change the text color, how will I able to do this?

My thoughts are to give <td> a class like status_color and add to the if condition:

 if (status === null) {
    status_color = (code to change class text color)
    g_status = 'Inactive'

Any help would be appreciated thanks

Aucun commentaire:

Enregistrer un commentaire