Skip to content
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 limit(callable $callback): static
*/
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;
$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);
call_user_func_array($this->limitCallback, [$this->query]);
} else {
$this->query->skip($this->request->input('start'))->take($limit);
}

$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,

];