mardi 8 octobre 2019

Datatables - replacing value with icon works with one cell but not two

Using Laravel 5.8 and Yajra datatables I have a table and I want to replace 1 with an icon or if 0 return a blank.

In my javascript I have:

  "columnDefs": [{
                  "targets": 5,
                  "render": function ( data, type, row ) {
                    if ( data == "1" )
                      {return '<i class="fas fa-check-circle"></i>';}
                    else if ( data == "0" )
                     { return ' ';}
                  },
                 }],

This works fine

enter image description here

but my problem is adding a second cell:

"columnDefs": [{
                  "targets": 5,
                  "render": function ( data, type, row ) {
                    if ( data == "1" )
                      {return '<i class="fas fa-check-circle"></i>';}
                    else if ( data == "0" )
                     { return ' ';}
                  },
                  "targets": 6,
                  "render": function ( data, type, row ) {
                    if ( data == "1" )
                      {return '<i class="fas fa-check-circle"></i>';}
                    else if ( data == "0" )
                     { return ' ';}
                  },

          }],

The first column (5) is back to zeros and ones but the column 6 is correct.

enter image description here

Help greatly appreciated indeed!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire