From 98b6e0e3ab7e9fc3f39116579b8e3db4a82090ae Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Sun, 25 Oct 2020 15:21:59 +0600 Subject: [PATCH 1/6] Hard Limit in Config (for Pagination) https://github.com/yajra/laravel-datatables/issues/2493 --- src/QueryDataTable.php | 2 ++ src/config/datatables.php | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index e44440b7..add12589 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -594,7 +594,9 @@ public function limit(callable $callback) */ public function paging() { + $max_record_per_page = $this->config->get('datatables.max_record_per_page', 0); $limit = (int) $this->request->input('length') > 0 ? $this->request->input('length') : 10; + $limit = ($max_record_per_page > 0 && $limit > $max_record_per_page) ? $max_record_per_page : $limit; if (is_callable($this->limitCallback)) { $this->query->limit($limit); call_user_func_array($this->limitCallback, [$this->query]); diff --git a/src/config/datatables.php b/src/config/datatables.php index ed2e36f7..944333ab 100644 --- a/src/config/datatables.php +++ b/src/config/datatables.php @@ -119,4 +119,10 @@ 'options' => 0, ], + /** + * Maximum record per page + * Set 0 for unlimited record + */ + 'max_record_per_page' => 100, + ]; From 8a9a065d3a74bb9d5d0cf49945b75973cd177426 Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Sun, 25 Oct 2020 15:29:28 +0600 Subject: [PATCH 2/6] CS Fix --- src/QueryDataTable.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index add12589..66a0ad78 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -594,9 +594,11 @@ public function limit(callable $callback) */ public function paging() { + $max_record_per_page = $this->config->get('datatables.max_record_per_page', 0); $limit = (int) $this->request->input('length') > 0 ? $this->request->input('length') : 10; $limit = ($max_record_per_page > 0 && $limit > $max_record_per_page) ? $max_record_per_page : $limit; + if (is_callable($this->limitCallback)) { $this->query->limit($limit); call_user_func_array($this->limitCallback, [$this->query]); From 3ca87912f8d99530502b1c9c5a4848b1e274ec17 Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Sun, 25 Oct 2020 15:31:21 +0600 Subject: [PATCH 3/6] CS Fix --- src/QueryDataTable.php | 6 +++--- src/config/datatables.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index 66a0ad78..9c78619c 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -594,10 +594,10 @@ public function limit(callable $callback) */ public function paging() { - + $max_record_per_page = $this->config->get('datatables.max_record_per_page', 0); - $limit = (int) $this->request->input('length') > 0 ? $this->request->input('length') : 10; - $limit = ($max_record_per_page > 0 && $limit > $max_record_per_page) ? $max_record_per_page : $limit; + $limit = (int) $this->request->input('length') > 0 ? $this->request->input('length') : 10; + $limit = ($max_record_per_page > 0 && $limit > $max_record_per_page) ? $max_record_per_page : $limit; if (is_callable($this->limitCallback)) { $this->query->limit($limit); diff --git a/src/config/datatables.php b/src/config/datatables.php index 944333ab..82aa2aa7 100644 --- a/src/config/datatables.php +++ b/src/config/datatables.php @@ -121,7 +121,7 @@ /** * Maximum record per page - * Set 0 for unlimited record + * Set 0 for unlimited record. */ 'max_record_per_page' => 100, From 1d81c26ca4531e3145ec59046035002c413cc310 Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Sun, 25 Oct 2020 15:31:55 +0600 Subject: [PATCH 4/6] CS fix --- src/QueryDataTable.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index 9c78619c..038a9bd8 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -594,7 +594,6 @@ public function limit(callable $callback) */ public function paging() { - $max_record_per_page = $this->config->get('datatables.max_record_per_page', 0); $limit = (int) $this->request->input('length') > 0 ? $this->request->input('length') : 10; $limit = ($max_record_per_page > 0 && $limit > $max_record_per_page) ? $max_record_per_page : $limit; From 97668a220cbe3335865d5308df5cffdd005cd4f4 Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Sun, 1 Nov 2020 21:10:52 +0600 Subject: [PATCH 5/6] Update datatables.php Typo Fixed --- src/config/datatables.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/datatables.php b/src/config/datatables.php index 82aa2aa7..270b7670 100644 --- a/src/config/datatables.php +++ b/src/config/datatables.php @@ -120,9 +120,9 @@ ], /** - * Maximum record per page + * Maximum records per page * Set 0 for unlimited record. */ - 'max_record_per_page' => 100, + 'max_records_per_page' => 100, ]; From c255c67439123b941b5d6c115b9463687402e5ff Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Sun, 1 Nov 2020 21:12:35 +0600 Subject: [PATCH 6/6] Update QueryDataTable.php Typo Fixed --- src/QueryDataTable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index 038a9bd8..49e9d83d 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -594,9 +594,9 @@ public function limit(callable $callback) */ public function paging() { - $max_record_per_page = $this->config->get('datatables.max_record_per_page', 0); + $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_record_per_page > 0 && $limit > $max_record_per_page) ? $max_record_per_page : $limit; + $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);