Any help?
May 14, 2019
5
Level 5
DataTables Sorting & Searching not working
I am using data tables in Laravel. The values are inserted with dynamic blade syntax. When I click ordering, it does not sort. Searching returns no match even though I provide the correct values. How do I solve this? NB: Looking in the chrome console, I see the table body changes state.
//Table cases javascritpt
$(document).ready( function () {
$('#table_id').DataTable();
} );
$.extend( $.fn.dataTable.defaults, {
ordering: true,
searching:true,
select: true,
"order": [[ 0, 'desc' ], [ 1, 'desc' ], [2, 'desc'], [3, 'desc']]
} );
<table class="table table-striped table-bordered" id="table_id">
<thead>
<tr>
<th>Case Number</th>
<th>Case Form</th>
<th>Patient Name</th>
<th>Date Created</th>
<th>Status</th>
</tr>
</thead>
@foreach ($project as $project)
<tbody>
<tr>
<td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->case_number}}</a></td>
@if ($project->services0)
<td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->services0}}</a></td>
@elseif ($project->services1)
<td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->services1}}</a></td>
@elseif ($project->services2)
{{-- <td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->services2 . ' ' . $project->mockup0}}</a></td> --}}
<td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->services2 . ' ' . $project->mockup0 . ' ' . $project->mockup1}}</a></td>
@endif
</tr>
</tbody>
@endforeach
</table>
Level 11
just ignore tbody in foreach loop like below
<table class="table table-striped table-bordered" id="table_id">
<thead>
<tr>
<th>Case Number</th>
<th>Case Form</th>
<th>Patient Name</th>
<th>Date Created</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach ($project as $project)
<tr>
<td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->case_number}}</a></td>
@if ($project->services0)
<td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->services0}}</a></td>
@elseif ($project->services1)
<td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->services1}}</a></td>
@elseif ($project->services2)
{{-- <td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->services2 . ' ' . $project->mockup0}}</a></td> --}}
<td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->services2 . ' ' . $project->mockup0 . ' ' . $project->mockup1}}</a></td>
@endif
</tr>
@endforeach
</tbody>
</table>
Please or to participate in this conversation.