when the js responds, the data has already been ordered by
example image response js :
example controller and query :
$query = Verifikasi_tte::join('surat_ttes', 'surat_ttes.id', '=', 'verifikasi_ttes.surat_tte_id')
->join('users', 'users.id', '=', 'surat_ttes.user_id')
->join('jenis_surat_ttes', 'jenis_surat_ttes.id', '=', 'surat_ttes.jenis_surat_tte_id')
->select('surat_ttes.id','surat_ttes.klasifikasi','surat_ttes.no_surat','surat_ttes.tgl_surat','surat_ttes.created_at',
'jenis_surat_ttes.nama_jenis_surat','users.name','verifikasi_ttes.surat_tte_id','verifikasi_ttes.status')
->orderBy('surat_ttes.id','DESC')->get();
return Datatables::of($query)
example view in ajax datables :
<script type="text/javascript">
$(function (e) {
$('#data-table').DataTable({
pageLength: 10,
processing: true,
serverSide: true,
stateSave: true,
ajax: "{{ url ('/verifikasi/data') }}",
columns: [
{data: 'name', name: 'name'},
{data: 'nama_jenis_surat', name: 'nama_jenis_surat'},
{data: 'no_surat', name: 'no_surat'},
{data: 'dates', name: 'dates'},
{data: 'status', name: 'status'},
{data: 'action', name: 'action', orderable: false, searchable: false}
]
});
});
</script>
is there something wrong with my controller?
2
Answers
because I use soft delete, so if to use the query builder it might not be possible for soft delete but eloquent, now here I combine eloquent with query builder, and I have tried not to use get() it works but to search data in the datatables package yajra there was an error in the form of the column field from the join query was not found
example image error search :
if example not use get() :
when I create a column in the form of a function, the return result of the query variable :
this method works and no error message appears in the column datatables, but what happens is that the search for query results in the datatables doesn't work .., is there anything to add to the ajax datatables yajra?, or change the controller in the query totally?
example image search datatables not working :
Try removing the
get()
function in the controller.This happens because the Datatables plugin wants a eloquent query object to do the sorting and searching features.
Also, the Table definition of your JS code should match the table column names correctly: