vendredi 16 août 2019

How to apply switch statement for multi columns in datatables

I have a laravel project that implements datatables to display data. I want to use some labels to format some columns on the table.

The problem now is having a second switch statement , the first one is working fine and the formatting is showing up fine.

columns: [
        { data: 'id', name: 'id' },
        { data: 'name', name: 'name' },
        { data: 'role_id', name: 'role_id' },
        { data: 'phone', name: 'phone' },
        { data: 'email', name: 'email' },
        { data: 'status', name: 'status' },
        { data: 'created_at', name: 'created_at' },
        { data: 'action', name: 'action' }
        ],
columnDefs : [
        { targets : [5],
          render : function (data, type, row) {
            switch(data) {
               case 0 : return '<span class="label label-danger">Inactive</span>'; 
               break;
               case 1 : return '<span class="label label-primary">Active</span>'; 
               break;
               case 2 : return '<span class="label label-danger">Suspended</span>'; 
               break;

            }
        }
},

I want to have column 2 and 5 formatted with labels, how to achieve this ?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2HcaLvH
via IFTTT

Aucun commentaire:

Enregistrer un commentaire