Change Badge Color In JS By Value

37 views Asked by At

I'm new in javascript. I try to make the badge color change according to the value. I've tried but the output is error badge

<th>
    <select class="select2-placeholder form-control" id="sIsLocked">
        <option value="">Pilih</option>
        <option value="false">Un Locked</option>
        <option value="true">Locked</option>
            
    </select>
</th>


render: function (data, type, row, meta) {
    switch (data) {
        case false:
            return '<span class="badge bg-success">Un Locked</span>';
        case true:
            return '<span class="badge rounded-pill bg-secondary">Locked</span>';
        default:
            return '<span class="badge badge-danger badge-pill">Error!</span>';
            
    }
}
1

There are 1 answers

0
Thanga Babu On

I think the problem is parameter data is not a boolean type. Print the data using console.log() and post it here.