【发布时间】:2021-09-21 12:01:43
【问题描述】:
我有一个可以从数据库中获取数据的表。在这里,我使用两个不同的表来匹配记录,如果两个表数据都匹配,则相应地获取值。数据库中的值是“,”分隔的,我可以使用explode函数进行拆分。现在的问题是数据库中的每个元素都以“,”开头,并且它将第一行返回为空白。 现在,当我使用 Datatable 显示数据时,排序在这里不起作用尝试了来自不同博客的太多解决方案,但对我没有任何帮助。我猜是因为它返回第一行,因为空白排序不起作用。
这是我的看法:
<table id="tablevar" class="table table-sm">
<thead>
<tr>
<th>
Top Correlators
</th>
<th>
Positive/Negative Correlation
</th>
</tr>
</thead>
@foreach(explode(', ', $detail->Topcorrelators) as $row)
<tr>
<td>
{{ $row }}
</td>
@foreach($Correlations_list as $corr)
@if($corr->Variable == $row )
<td>
@if($corr->Corr > 0)
<div class="progress">
<div class="progress-bar large progress-bar-striped" role="progressbar" style="width: 100%;background-color:#e9ecef;" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar progress-bar-striped" role="progressbar" style="width: 100%;background-color:#CA0088 " aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
</div>
Positive Correlator( {{ $corr->Corr }} )
@else
<div class="progress">
<div class="progress-bar large progress-bar-striped" role="progressbar" style="width: 100%;background-color:#EAB330;" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar large progress-bar-striped" role="progressbar" style="width: 100%;background-color:#e9ecef;" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
</div>
Negative Correlator( {{ $corr->Corr }} )
@endif
</td>
@endif
@endforeach
</tr>
@endforeach
</table>
这是我的控制器代码:
$Correlations_list=Correlation::all();
return view('admin.members.Detailspage',compact('detail','Correlations_list'));
这是我的脚本:
$('#tablevar').DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": true,
});
有什么帮助吗?
【问题讨论】:
-
为什么不检查空值并跳过该行?
-
@Frnak 你能告诉我如何在上面的代码中做到这一点...?
-
@Frnak 因为我是 laravel 的新手,所以我不确定如何在刀片中做到这一点?
标签: jquery laravel eloquent datatables yajra-datatable