I am trying to implement yajra datatables in one of my laravel application and this is the first time I am using yajra datatables required for server side processing. My table is showing records but when I try to search from the tables it does not search here is the code I am using.
Controller
$prospects = Prospect::
where('is_customer_of', NULL)
->where('type', 'Year-round')
->orWhere('type', NULL)
->orderBy('created_at', 'DESC')
->select('*');
return Datatables::of($prospects)
->editColumn('status', function($row) {
if ($row->status == 0) {
$html = '<span class="badge label-table badge-success">Untagged</span>';
} elseif ($row->status == 1) {
$html = '<span class="badge label-table badge-danger">Tagged</span>';
}
return $html;
})
->addColumn('untagged_date', function($row) {
if (Auth::user()->role == 'admin') {
if (UntaggedLog::getUntaggedData($row->id)) {
return date("Y-m-d", strtotime(UntaggedLog::getUntaggedData($row->id)->created_at));
} else {
return '-';
}
}
})
->addColumn('tagged_by', function($row) {
if ($row->tagged_by) {
$user = User::find($row->tagged_by)->name;
return $user;
} else {
return '-';
}
})
->addColumn('date_last_called', function($row) {
$callLogs = CallLogs::where('prospect_id', $row->id)
->orderBy('start_time', 'DESC')
->get();
if (count($callLogs) > 0) {
return date('Y-m-d', strtotime(CallLogs::getLastCalledDate($row->id)));
} else {
return '-';
}
})
->setRowAttr([
'data-href' => function ($row) {
return route('prospect-view', ['id' => $row->id, 'name' => $row->name]);
}])
->rawColumns(['status', 'Date Untagged'])
->make(true);
JS
$('#all_prospects_datatables').DataTable({
"pageLength": 100,
"lengthMenu": [[100, 500, 1000, -1], [100, 500, 1000, "All"]],
processing: true,
serverSide: true,
responsive: true,
bAutoWidth: false,
ajax: '/getIndexData',
"columnDefs": [
{"searchable": true}
],
columns: [
{data: 'status', name: 'status'},
{data: 'name', name: 'name'},
{data: 'city', name: 'city'},
{data: 'state', name: 'state'},
{data: 'timezone', name: 'timezone'},
{data: 'type', name: 'type'},
{data: 'created_at', name: 'created_at'},
{data: 'tagged_date', name: 'tagged_date'},
{data: 'untagged_date', name: 'untagged_date'},
{data: 'tagged_by', name: 'tagged_by'},
{data: 'date_last_called', name: 'date_last_called'}
]
});
Any help / hint will be much appreciated as I am trying to figure out the issue for like a day now.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire