Tambah sorting dan perbaiki lokasi perhitungan total record
Menambahkan logika sorting berdasarkan `sortOrder` dan `sortField` jika ada pada permintaan. Selain itu, memindahkan perhitungan total record ke posisi yang lebih tepat untuk menghindari pengaruh dari pagination.
This commit is contained in:
@@ -82,6 +82,16 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply sorting if provided
|
||||||
|
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||||
|
$order = $request->get('sortOrder');
|
||||||
|
$column = $request->get('sortField');
|
||||||
|
$query->orderBy($column, $order);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the total count of records
|
||||||
|
$totalRecords = $query->count();
|
||||||
|
|
||||||
// Apply pagination if provided
|
// Apply pagination if provided
|
||||||
if ($request->has('page') && $request->has('size')) {
|
if ($request->has('page') && $request->has('size')) {
|
||||||
$page = $request->get('page');
|
$page = $request->get('page');
|
||||||
@@ -91,16 +101,6 @@
|
|||||||
$query->skip($offset)->take($size);
|
$query->skip($offset)->take($size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the total count of records
|
|
||||||
$totalRecords = $query->count();
|
|
||||||
|
|
||||||
// Apply pagination if provided
|
|
||||||
if ($request->has('start') && $request->has('length')) {
|
|
||||||
$start = $request->get('start');
|
|
||||||
$length = $request->get('length');
|
|
||||||
$query->skip($start)->take($length);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the filtered count of records
|
// Get the filtered count of records
|
||||||
$filteredRecords = $query->count();
|
$filteredRecords = $query->count();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user