Skip to content

Commit f50ebd8

Browse files
committed
Fix with closue value implementation.
Use filteredQuery as callback parameter. Fix #1752
1 parent 3eeed5e commit f50ebd8

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/DataTableAbstract.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function with($key, $value = '')
340340
if (is_array($key)) {
341341
$this->appends = $key;
342342
} elseif (is_callable($value)) {
343-
$this->appends[$key] = value($value);
343+
$this->appends[$key] = $value;
344344
} else {
345345
$this->appends[$key] = value($value);
346346
}
@@ -683,12 +683,12 @@ protected function processResults($results, $object = false)
683683
*/
684684
protected function render(array $data)
685685
{
686-
$output = array_merge([
686+
$output = $this->attachAppends([
687687
'draw' => (int) $this->request->input('draw'),
688688
'recordsTotal' => $this->totalRecords,
689689
'recordsFiltered' => $this->filteredRecords,
690690
'data' => $data,
691-
], $this->appends);
691+
]);
692692

693693
if ($this->config->isDebugging()) {
694694
$output = $this->showDebugger($output);
@@ -702,6 +702,17 @@ protected function render(array $data)
702702
);
703703
}
704704

705+
/**
706+
* Attach custom with meta on response.
707+
*
708+
* @param array $data
709+
* @return array
710+
*/
711+
protected function attachAppends(array $data)
712+
{
713+
return array_merge($data, $this->appends);
714+
}
715+
705716
/**
706717
* Append debug parameters on output.
707718
*

src/QueryDataTable.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,4 +669,23 @@ protected function showDebugger(array $output)
669669

670670
return $output;
671671
}
672+
673+
/**
674+
* Attach custom with meta on response.
675+
*
676+
* @param array $data
677+
* @return array
678+
*/
679+
protected function attachAppends(array $data)
680+
{
681+
$appends = [];
682+
foreach ($this->appends as $key => $value) {
683+
if (is_callable($value)) {
684+
$appends[$key] = value($value($this->getFilteredQuery()));
685+
} else {
686+
$appends[$key] = $value;
687+
}
688+
}
689+
return array_merge($data, $appends);
690+
}
672691
}

0 commit comments

Comments
 (0)