Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: recordsFiltered Limit (Hard Limit in Config) #2565

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/QueryDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,16 @@
*/
public function addColumn($name, $content, $order = false): static
{
$max_records_per_page = $this->config->get('datatables.max_records_per_page', 0);
$limit = (int) $this->request->input('length') > 0 ? $this->request->input('length') : 10;

Check failure on line 621 in src/QueryDataTable.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, prefer-stable)

Cannot cast mixed to int.
$limit = ($max_records_per_page > 0 && $limit > $max_records_per_page) ? $max_records_per_page : $limit;
if (is_callable($this->limitCallback)) {
$this->query->limit($limit);

Check failure on line 624 in src/QueryDataTable.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, prefer-stable)

Parameter #1 $value of method Illuminate\Database\Query\Builder::limit() expects int, mixed given.
call_user_func_array($this->limitCallback, [$this->query]);
} else {
$this->query->skip($this->request->input('start'))->take($limit);

Check failure on line 627 in src/QueryDataTable.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, prefer-stable)

Parameter #1 $value of method Illuminate\Database\Query\Builder::skip() expects int, mixed given.

Check failure on line 627 in src/QueryDataTable.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, prefer-stable)

Parameter #1 $value of method Illuminate\Database\Query\Builder::take() expects int, mixed given.
}

$this->pushToBlacklist($name);

return parent::addColumn($name, $content, $order);
Expand Down
8 changes: 8 additions & 0 deletions src/config/datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,12 @@
* Callbacks needs to start by those terms, or they will be cast to string.
*/
'callback' => ['$', '$.', 'function'],

/**
* Maximum records per page
* Set 0 for unlimited record
* Do not use value under 10 if you are not using laravel-datatables-html.
*/
'max_records_per_page' => 0,

];
Loading