I have a boostrap table in which in a cell of each row I could load the value of an array converted to base 64, I would say because sometimes the property that maps that value could come in null:
<table id="tableOcMateriales" class="table table-condensed table-striped table-bordered table-hover dataTables_length" style="width: 100%; align-content: center">
<thead class="ColorHeaderTable">
<tr>
<th style="width: 20%">
@Html.DisplayNameFor(model => model.MaterialDescripcion)
</th>
<th style="display: none"></th>
</tr>
</thead>
<tbody class="celda">
@foreach (var item in Model)
{
<tr data-toggle="popover">
<td style="width: 20%">
@Html.DisplayFor(modelItem => item.MaterialDescripcion)
</td>
<td style="display: none">
@Html.DisplayFor(modelItem => item.ImagenB64)
</td>
</tr>
}
</tbody>
</table>
I am trying to show the image in a popover when the user clicks on the row of the Table, for that I am using this script:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$('#tableOcMateriales').on('click', 'tbody tr', function (event) {
var img;
if (!$(this).closest('tr').find('td').hasClass('dataTables_empty')) {
$(this).addClass('highlightchecked').siblings().removeClass('highlightchecked');
var imagenBase64 = $(this).closest('tr').find('td:eq(7)').text();
if (imagenBase64 !== "") {
img = '<div id ="image"><img src ="data:image/jpeg;base64,' + imagenBase64 + '\" style="width:370px;"/></div>"';
}
else {
img = '';
}
}
if (img !== "") {
var closebtn = $('<button/>', {
type: "button",
text: 'X',
id: 'close-preview',
style: 'font-size: initial;'
});
closebtn.attr("class", "close pull-right");
$('[data-toggle="popover"]').popover({
trigger: 'focus',
container: '.modal-body',
placement: 'auto',
title: "<strong>Preview</strong>" + $(closebtn)[0].outerHTML,
content: img,
html: true
}).popover('show').not(this).popover('hide');
}
$('body').on('click', '#close-preview', function (e) {
$('[data-toggle=popover]').popover('hide');
});
});
});
With the previous script I manage to show the popover but it shows me the same image in all the rows, I want that if the row does not contain the image value it does not show me the popover .