Logic not working as expected.
Logic not working as expected.
classic12
Posts: 228Questions: 60Answers: 4
in DataTables
Hi guys I have the following code which checks for the extension type and display accordingly.
The first section checks to see if it is an image.
The second if it is a video.
The third show id none of the above.
It is failing on ext = JPG ( ie it shows as a link ).
What am I doing wrong here please?
render: function(data, type, row)
{
if (data !== undefined ){
var ext = data.substr(data.lastIndexOf('.') + 1);
if ( (ext === 'jpeg' ) || ( ext === 'jpg' ) || ( ext === 'JPG' ) || ( ext === 'jp2' ) || ( ext === 'png' )|| ( ext === 'gif' ) || ( ext === 'pdf' ))
{
return '<img src=" ' + data + ' "' + imageSize + ' class="info1">';
}
// now check if it is a video
if ( (ext === 'mp4')|| ( ext === 'MOV' ))
{
return ' <video width="320" height="240" controls> <source src=" ' +data + ' " type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video>'
}
// last here so must be download
{
var fullPath = data.split('.')[0];
var filename = fullPath.replace(/^.*[\\\/]/, '');
return ' Click to Download <br/> <a href=" '+ data + ' " target="_blank" > '+ data + " </a> ";
}
} else { return '' };
}
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Not sure whether I really understood your problem but maybe you want to try this:
This removes whitespace from your substring and converts it to lower case.
Consequently you need to make these changes as well:
https://www.w3schools.com/jsref/jsref_trim_string.asp
https://www.w3schools.com/jsref/jsref_tolowercase.asp
Thanks,
that did the job but still not sure why....
Can't see any white space and I had JPG.
Glad that it helped! The white space can have been something invisible after the JPG. trim() removes whitespace before and after.