php - 如何在数据表中显示 2 张图像?
问题描述
我想使用 Datatable 和 Laravel 5.7 在表格中显示 2 张图像。图像正在显示,但视图表并不好。
这是我的表格 html:
<div class="col-sm-4">
<div class="row">
<table id="tableData" class="table table-bordered table-striped">
<thead>
<tr style="background-color:#3896D6;">
<th style="vertical-align: middle!important; text-align: center!important; color: white;" colspan="2">Image Data</th>
</tr>
<tr>
<th style="vertical-align: middle!important; text-align: center!important;">Image 1</th>
<th style="vertical-align: middle!important; text-align: center!important;">Image 2</th>
</tr>
</thead>
</table>
</div>
</div>
这就是我将图像渲染到表格的方式
$('#tableData').DataTable().destroy();
$('#tableData').dataTable({
paging: false,
info : false,
searching: false,
ajax : {
url : 'monitoring/getphoto/'+id,
method : 'GET',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
},
columns : [
{
"render": function (data, type, row) {
if (row.photo_position == 1) {
return '<img width=100 height=100 src="'+ row.photo_url +'">';
}else{
return '';
}
}
},
{
"render": function (data, type, row) {
if (row.photo_position == 2) {
return '<img width=100 height=100 src="'+ row.photo_url +'">';
}else{
return '';
}
}
}
],
columnDefs : [
{
"targets" : "_all",
"className": "text-center",
}
]
});
这是表格中显示的图像:
表格视图不太好,所以我该如何解决这个问题?
解决方案
<thead>
with<th>
仅用于标题。在您的“图像数据”的情况下。在该行之后,您需要关闭<thead>
with</thead>
并从 开始<tbody>
。在<tbody>
你使用<td>
而不是<th>
所以你的代码看起来像这样:
<div class="col-sm-4">
<div class="row">
<table id="tableData" class="table table-bordered table-striped">
<thead>
<tr style="background-color:#3896D6;">
<th style="vertical-align: middle!important; text-align: center!important; color: white;" colspan="2">Image Data</th>
</tr>
</thead>
<tbody>
<tr>
<td style="vertical-align: middle!important; text-align: center!important;">Image 1</td>
</tr>
<tr>
<td style="vertical-align: middle!important; text-align: center!important;">Image 2</td>
</tr>
</tbody>
</table>
</div>
</div>
推荐阅读
- javascript - Express.js 为什么放置 app.use() 会影响测试结果?
- typescript - Nestjs Swagger - import types wrong node module
- javascript - Is it possible to make POST/Update request at selected hour? ReactJS
- javascript - 如何在javascript中更改项目颜色?
- c++ - C++ Builder: Pass Onclick-Event of Button on Form1 to Button on Form2
- java - Amazon FireTV get name of device
- android - ProgressBar 从代码中不会在 Android Studio 中可见
- python - 将来自不同excel文件的工作表加入一个工作簿python
- json - curl POST没有给我结果
- c# - Drawing library calculate ranges and midpoints to draw a star