From f50ebd8f3a3dd7cd008a6072f528e523382912ae Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 3 Jun 2018 08:47:56 +0800 Subject: [PATCH 1/3] Fix with closue value implementation. Use filteredQuery as callback parameter. Fix #1752 --- src/DataTableAbstract.php | 17 ++++++++++++++--- src/QueryDataTable.php | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/DataTableAbstract.php b/src/DataTableAbstract.php index 57063dc4..fc900d9f 100644 --- a/src/DataTableAbstract.php +++ b/src/DataTableAbstract.php @@ -340,7 +340,7 @@ public function with($key, $value = '') if (is_array($key)) { $this->appends = $key; } elseif (is_callable($value)) { - $this->appends[$key] = value($value); + $this->appends[$key] = $value; } else { $this->appends[$key] = value($value); } @@ -683,12 +683,12 @@ protected function processResults($results, $object = false) */ protected function render(array $data) { - $output = array_merge([ + $output = $this->attachAppends([ 'draw' => (int) $this->request->input('draw'), 'recordsTotal' => $this->totalRecords, 'recordsFiltered' => $this->filteredRecords, 'data' => $data, - ], $this->appends); + ]); if ($this->config->isDebugging()) { $output = $this->showDebugger($output); @@ -702,6 +702,17 @@ protected function render(array $data) ); } + /** + * Attach custom with meta on response. + * + * @param array $data + * @return array + */ + protected function attachAppends(array $data) + { + return array_merge($data, $this->appends); + } + /** * Append debug parameters on output. * diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index 270a5d19..fd0bad76 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -669,4 +669,23 @@ protected function showDebugger(array $output) return $output; } + + /** + * Attach custom with meta on response. + * + * @param array $data + * @return array + */ + protected function attachAppends(array $data) + { + $appends = []; + foreach ($this->appends as $key => $value) { + if (is_callable($value)) { + $appends[$key] = value($value($this->getFilteredQuery())); + } else { + $appends[$key] = $value; + } + } + return array_merge($data, $appends); + } } From f174b7825cb1212f1efa9c5f675ea47c2e8d310f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 3 Jun 2018 08:51:05 +0800 Subject: [PATCH 2/3] Fix CS. --- src/QueryDataTable.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index fd0bad76..57264723 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -686,6 +686,7 @@ protected function attachAppends(array $data) $appends[$key] = $value; } } + return array_merge($data, $appends); } } From 5c9a9d3d24183dc6d33078d1da76ed09b34bad9e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 3 Jun 2018 09:04:12 +0800 Subject: [PATCH 3/3] Bump v8.6.1 :rocket: --- CHANGELOG.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f24723..d9eefb8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ ### [Unreleased] +### [v8.6.1] - 2018-06-03 + +- Fix/Enhance with closure value implementation. [#1758] +- Use filteredQuery as callback parameter. +- Fix [#1752] + ### [v8.6.0] - 2018-05-18 - Add support for manual setting of filtered count [#1743], credits to [@forgottencreature] @@ -208,7 +214,8 @@ return (new CollectionDataTable(User::all())->toJson(); - Fix orderColumn api where related tables are not joined. - Fix nested with relation search and sort function. -[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v8.6.0...8.0 +[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v8.6.1...8.0 +[v8.6.1]: https://github.com/yajra/laravel-datatables/compare/v8.6.0...v8.6.1 [v8.6.0]: https://github.com/yajra/laravel-datatables/compare/v8.5.2...v8.6.0 [v8.5.2]: https://github.com/yajra/laravel-datatables/compare/v8.5.1...v8.5.2 [v8.5.1]: https://github.com/yajra/laravel-datatables/compare/v8.5.0...v8.5.1 @@ -274,6 +281,7 @@ return (new CollectionDataTable(User::all())->toJson(); [#1737]: https://github.com/yajra/laravel-datatables/pull/1737 [#1741]: https://github.com/yajra/laravel-datatables/pull/1741 [#1743]: https://github.com/yajra/laravel-datatables/pull/1743 +[#1758]: https://github.com/yajra/laravel-datatables/pull/1758 [#1626]: https://github.com/yajra/laravel-datatables/issues/1626 [#1617]: https://github.com/yajra/laravel-datatables/issues/1617 @@ -290,6 +298,7 @@ return (new CollectionDataTable(User::all())->toJson(); [#1471]: https://github.com/yajra/laravel-datatables/issues/1471 [#1739]: https://github.com/yajra/laravel-datatables/issues/1739 [#1516]: https://github.com/yajra/laravel-datatables/issues/1516 +[#1752]: https://github.com/yajra/laravel-datatables/issues/1752 [laravel-datatables-fractal]: https://github.com/yajra/laravel-datatables-fractal