Using the result of one column variable to dictate what is assigned to another column variable

Using the result of one column variable to dictate what is assigned to another column variable

bytecbytec Posts: 37Questions: 10Answers: 0

Hi all,
I have a table column "ImageName" that contains the name of an image or mp4 file along with a column that contains a "1" or a "2"..
If the table column "FileType" conatins "1" the "ImageName" is an image and if "FileType" conatins "2" the "ImageName" is an video.

var noimage = "noimage.png";
var videoimage "videoimage.png";
var imagepathroom = "../../../../signage/signage_images/promotions/<?php echo $_SESSION['room'];?>/";

Based on the above what I would like to do is:

if the column "FileType" contains "1" display the image relating to the name in "ImageName", or
if the column "FileType" contains "2" display "videoimage",
if column "ImageName" is empty display an image "noimage".

The code I have so far:

columns: [
  { data: "FileType", "visible":false },
  { data: "ImageImage", width: '10%', render : function (data, type){
    if (data === "") {
      return '<img src="' + noimageroom + '" class="WayfinderSignageImage"/>';
    } else {
      return '<img src="' + imagepathroom + '' +data+'" class="WayfinderSignageImage" />';
    }
  }
]

How can I combine the result of data: "FileName" to dictate which image is given to data: "ImageImage"

Thanks in advance.

Answers

Sign In or Register to comment.