在自定义查询上排序不适用于Paginator

时间:2018-09-29 20:26:15

标签: cakephp-3.0

尝试使分页器正常工作,这样我就可以对报告进行排序,但是它不起作用。没有列将排序。有没有办法用Paginator做到这一点?这是CakePHP 3.5.17。

查询

    $objQuery = TableRegistry::get('Reservation')->find();

    $unconfirmed = $objQuery->newExpr()->addCase(
        $objQuery->newExpr()->add(['Reservation.status' => 'unconfirmed']),
        1,
        'integer'
    );

    $objQuery->select([
            'Publisher.id',
            'Publisher.name',
            'count' => $objQuery->func()->count('Reservation.publisher_id'),
            'unconfirmed' => $objQuery->func()->count($unconfirmed),
            'sum_total' => $objQuery->func()->sum('Reservation.total_charge * Reservation.usd_value'),
            'sum_room_charge' => $objQuery->func()->sum('Reservation.room_charge * Reservation.usd_value'),
            'sum_nights' => $objQuery->func()->sum(
                'datediff(ReservationPropertyAccommodation.checkout, ReservationPropertyAccommodation.checkin)'
            ),
        ])
        ->contain([
            'Publisher',
            'ReservationPropertyAccommodation'
        ]);

    $objQuery->group('publisher_id');

    $this->paginate = [
        'limit' => 100,
        'order' => ['Publisher.name' => 'asc'],
    ];

    $reservations = $this->paginate($objQuery);

HTML / Paginator视图帮助器

<th scope="col"><?= $this->Paginator->sort('publisher.name', 'Publisher') ?></th>
<th scope="col"><?= $this->Paginator->sort('count', 'Reservations') ?></th>
<th scope="col"><?= $this->Paginator->sort('unconfirmed', 'Unconfirmed') ?></th>
<th scope="col"><?= $this->Paginator->sort('sum_nights', 'Nights Booked') ?></th>
<th scope="col">ADR</th>
<th scope="col"><?= $this->Paginator->sort('sum_room_charge', 'Room Revenue') ?></th>

我想我可以对诸如“数据表”之类的东西使用客户端排序,但是我仍然对如何解决这个问题很感兴趣。

0 个答案:

没有答案