Laravel yajra表分页服务器端,点击第二页后无法点击第三页
P粉563831052
P粉563831052 2023-09-04 20:24:03
0
1
610
<p>基本上,这是第一页(可以看第一张图),总共有8条数据,每页会显示2条数据。 第一张图片</p> <p>所以当我点击第二页时,第三页就会丢失,无法点击。你可以看到第二张图片(这是第二页的第二张图片,但是正如你所看到的,没有按钮让我点击第三页)</p> <p>正如您在下面看到的,我尝试添加数据表并将 ->setOffset($start) 放入代码中。但它不起作用。请任何人帮助我。</p>
公共函数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) 作为 ttl_kid,SUM(event_reservations.total_adults + event_reservations.total_kids) 作为 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 作为 event_name,outlets.name 作为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) ? $请求->开始:0;

        返回数据表::of($reservationList)
        ->setOffset($start)
        ->addIndexColumn()  
            -> make(真);
    }</pre></p>            
P粉563831052
P粉563831052

全部回复(1)
P粉988025835

我已经得到了答案,我只是更改了一些代码并删除了一些代码:

if (!empty($req['start'])) {
        $query->skip($req['start']);


    }

    if (!empty($req['start'])) {
        $query->take($req['length']);
    }

这是该函数的完整代码:

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']);
    }

    $query->orderBy("reservation_date");

    $reservationList = $query->get();

    return Datatables::of($reservationList)
    ->make(true);
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板