44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\DataTables;
|
|
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Yajra\DataTables\CollectionDataTable;
|
|
|
|
/** P1 searches and sorts scalar columns; nested payment histories are display data. */
|
|
class P1CollectionDataTable extends CollectionDataTable
|
|
{
|
|
protected function defaultOrdering(): void
|
|
{
|
|
$criteria = $this->request->orderableColumns();
|
|
if ($criteria !== []) {
|
|
// Do not flatten and rebuild every employee's entire payment history to sort names.
|
|
$this->collection = $this->collection->sort($this->getSorter($criteria));
|
|
}
|
|
}
|
|
|
|
public function make(bool $mDataSupport = true): JsonResponse
|
|
{
|
|
try {
|
|
$this->validateMinLengthSearch();
|
|
$this->totalRecords = $this->totalCount();
|
|
|
|
if ($this->totalRecords) {
|
|
$this->filterRecords();
|
|
$this->ordering();
|
|
$this->paginate();
|
|
|
|
// Format and escape only the requested page, including its nested detail data.
|
|
$results = $this->results();
|
|
$processed = $this->processResults($results, $mDataSupport);
|
|
$this->collection = collect($this->transform($results, $processed));
|
|
}
|
|
|
|
return $this->render($this->collection->values()->all());
|
|
} catch (Exception $exception) {
|
|
return $this->errorResponse($exception);
|
|
}
|
|
}
|
|
}
|