May 29, 2024
0
Level 2
Laravel YarjaBox Datatables ajax
I have the laravel YarjaBox datatable ajax. Here is the controller code.
if ($request->ajax()) {
$query = Feedback::query();
// Apply search filter
if ($request->has('search') && $request->search['value'] != '') {
$search = $request->search['value'];
$query->where(function ($q) use ($search) {
$q->where('student_id', 'LIKE', "%{$search}%");
});
}
// Get total count before applying limit
$totalData = $query->count();
// Handle pagination parameters
$start = $request->input('start', 0);
$length = $request->input('length', 10); // Default to 10 if not provided
$data = $query->latest()->offset($start)->limit($length)->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('actions', 'superadmin.feedbacks.feedback.actions')
->rawColumns(['actions'])
->setTotalRecords($totalData) // Set the total number of records
->setFilteredRecords($totalData) // Set the total number of filtered records
->make();
}
Everything is good. Search working properly pagination coming. But when i selet page 2 it is not showing data in the table. (but data is filetered)
Please or to participate in this conversation.