Laravel yajra表格分頁伺服器端,點選第二頁後無法點選第三頁
P粉563831052
2023-09-04 20:24:03
<p>基本上,這是第一頁(可以看第一張圖),總共有8個數據,每頁會顯示2個數據。
第一張圖</p>
<p>所以當我點擊第二頁時,第三頁就會遺失,無法點擊。你可以看到第二張圖片(這是第二頁的第二張圖片,但是正如你所看到的,沒有按鈕讓我點擊第三頁)</p>
<p>如您在下面看到的,我嘗試新增資料表並將 ->setOffset($start) 放入程式碼中。但它不起作用。請任何人幫助我。 </p>
<pre class="brush:php;toolbar:false;">public function reservationListing(Request $request)
{
$req = $request->all();
$query = EventReservation::selectRaw("reservation_date,event_reservations.outlet_id,event_reservations.event_id,SUM(event_reservations.total_adults) as ttl_adult,
SUM(event_reservations.total_kids) as ttl_kid,SUM(event_reservations.total_adults event_reservations.total_kids)as ttl_pax,
SUM(CASE WHEN event_reservations.total_attendees is NULL then 0 Else event_reservations.total_attendees End) as ttl_attended,
SUM(CASE WHEN payment_status = 'pending' THEN 1 ELSE 0 END) as ttl_pending,SUM(CASE WHEN payment_status = 'paid' THEN 1 ELSE 0 END) as ttl_paid,
events.name as event_name,outlets.name as outlet_name")
->leftjoin("events", "events.id", "=", "event_reservations.event_id")
->leftjoin("outlets", "outlets.id", "=", "event_reservations.outlet_id")
->groupby('reservation_date')
->groupby('outlet_id')
->groupby('event_id');
if (!empty($req['date_to']) && !empty($req['date_to'])) {
$query->whereRaw("DATE(reservation_date) BETWEEN '".$req['date_from']."' AND '".$req['date_to']."'");
}
if (!empty($req['outlet_id'])) {
$query->where("event_reservations.outlet_id", $req['outlet_id']);
}
if (!empty($req['event_id'])) {
$query->where("event_reservations.event_id", $req['event_id']);
}
if (!empty($req['start'])) {
$query->skip($req['start']);
}
if (!empty($req['start'])) {
$query->take($req['length']);
}
$query->orderBy("reservation_date");
$reservationList = $query->get();
$start = ($request->start) ? $request->start : 0;
return Datatables::of($reservationList)
->setOffset($start)
->addIndexColumn()
->make(true);
}</pre></p>
我已經得到了答案,我只是更改了一些程式碼並刪除了一些程式碼:
這是函數的完整程式碼: