Вид
<script>
var table = $('#applications').dataTable(
{
processing: true,
serverSide: true,
"ajax": "{{ URL::route("front.leave_applications") }}",
"aaSorting": [[0, "asc"]],
columns: [
{data: 'id', name: 'id'},
{data: 'start_date', name: 'start_date'},
{data: 'days', name: 'days'},
{data: 'leaveType', name: 'leaveType'},
{data: 'halfDayType', name: 'halfDayType'},
{data: 'reason', name: 'reason'},
{data: 'applied_on', name: 'applied_on'},
{data: 'application_status', name: 'application_status'},
{data: 'edit', name: 'edit', "bSortable": false}
],
"sPaginationType": "full_numbers",
"language": {
"lengthMenu": "Display _MENU_ records per page",
"info": "Showing page _PAGE_ of _PAGES_",
"emptyTable": "{{trans('messages.noDataTable')}}",
"infoFiltered": "(filtered from _MAX_ total records)",
"search": "{{trans('core.search')}}:"
},
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
var oSettings = this.fnSettings();
$("td:first", nRow).html(oSettings._iDisplayStart + iDisplayIndex + 1);
return nRow;
}
});
</script>
<table class="table table-striped table-bordered table-hover" id="applications">
<thead>
<tr>
<th>{{trans('core.id')}}</th>
<th>{{trans('core.date')}}</th>
<th class="text-center">{{trans('core.days')}}</th>
<th>{{trans('core.type')}}</th>
<th>{{trans('core.Leave type')}}</th>
<th>{{trans('core.reason')}}</th>
<th>{{trans('core.appliedOn')}}</th>
<th>{{trans('core.status')}}</th>
<th>{{trans('core.action')}}</th>
</tr>
</thead>
<tbody>
<tr>
<td> {{-- ID from Contoller ajaxload------}} </td>
<td class="text-center"> {{-- Date from Contoller ajaxload----}} </td>
<td> {{-- Days from Contoller ajaxload----}} </td>
<td> {{-- Leavetype from Contoller ajaxload--}} </td>
<td> {{-- HalfDayType from Controller ajaxload--}}</td>
<td> {{-- Reason from Contoller ajaxload----}} </td>
<td> {{-- Applied on from Contoller ajaxload---}} </td>
<td> {{-- Status from Contoller ajaxload----}} </td>
<td> {{-- Action from Contoller ajaxload----}} </td>
</tr>
</tbody>
</table>
Контроллер
public function ajaxApplications()
{
$result = LeaveApplication::select('leave_applications.id', 'start_date', 'end_date', 'days', 'leaveType', 'reason', 'applied_on', 'application_status', 'halfDayType')
->whereNotNull('application_status')
->where("leave_applications.employee_id", $this->employee->id)
->orderBy('leave_applications.id', 'desc')->get();
return \DataTables::of($result)->editColumn('start_date', function ($row) {
return date('d/m/Y', strtotime($row->start_date)) . (isset($row->end_date) ? "<br>to<br>" . date('d/m/Y', strtotime($row->end_date)) : '');
})->editColumn('applied_on', function ($row) {
return date('d-M-Y', strtotime($row->applied_on));
})->editColumn('leaveType', function ($row) {
$leave = ($row->halfDayType == 'yes') ? 'half day -' . $row->leaveType : $row->leaveType;
return $leave;
})->editColumn('halfDayType', function ($row){
if($row->halfDayType == 'fl')
{
return '<a href="javascript:void(0)" class="btn btn-danger">Full Day Leave</a>';
}
else if($row->halfDayType == 'hl')
{
return '<a href="javascript:void(0)" class="btn btn-warning">Half Day Leave</a>';
}
else if($row->halfDayType == 'sl')
{
return '<a href="javascript:void(0)" class="btn btn-primary">Short Day Leave';
}
})->editColumn('reason', function ($row) {
return strip_tags(Str::limit($row->reason, 50));
})->editColumn('application_status', function ($row) {
$color = ['pending' => 'warning', 'approved' => 'success', 'rejected' => 'danger'];
return "<span class='label label-{$color[$row->application_status]} text-uppercase'>{$row->application_status}</span>";
})->removeColumn('halfDayType')->removeColumn('end_date')
->addColumn('edit', function ($row) {
if($row->application_status == 'pending')
{
return '<a href="editLeave/'.$row->id.'" class="btn-u btn-u-xs btn-u-green" style="margin-bottom:5px;"><i class="fa fa-edit"></i></a>
<button class="btn-u btn-u-xs btn-u-blue" onclick="show_application(' . $row->id . ');return false;" ><i class="fa fa-eye"></i></button>';
}
else
{
return '<button class="btn-u btn-u-xs btn-u-blue" onclick="show_application(' . $row->id . ');return false;" ><i class="fa fa-eye"></i></button>';
}
})
->rawColumns(['start_date', 'applied_on', 'leaveType', 'reason', 'edit', 'application_status'])
->make();
}
В этом коде я просто хочу показать halfDayType
значение в моем Leave Type
заголовок таблицы, и у меня проблема с заголовком таблицы, если я пишу <th>{{trans('core.Leave type')}}</th>
, то это выглядит как core.Leave Type
, но у меня есть ошибка, т.е. DataTables warning: table id=applications - Requested unknown parameter 'halfDayType' for row 0
. Я не знаю, почему это появляется. Итак, как я могу решить эту проблему? Пожалуйста, помогите мне.
Спасибо.