diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index aea42844..1f6d22d2 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -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); diff --git a/src/config/datatables.php b/src/config/datatables.php index 08912643..964ac4e3 100644 --- a/src/config/datatables.php +++ b/src/config/datatables.php @@ -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, + ];