Skip to content

Commit 7ca4169

Browse files
authored
Merge pull request #419 from amvisor/custom-callback-name
introduce the ability to pass a custom name for a callback column
2 parents 4420afa + f56d767 commit 7ca4169

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Column.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Mediconesystems\LivewireDatatables;
44

5+
use Closure;
56
use Illuminate\Support\Facades\DB;
67
use Illuminate\Support\Str;
78
use Mediconesystems\LivewireDatatables\Http\Livewire\LivewireDatatable;
@@ -97,11 +98,25 @@ public static function raw($raw)
9798
return $column;
9899
}
99100

100-
public static function callback($columns, $callback, $params = [])
101-
{
101+
/**
102+
* Make a callback function.
103+
*
104+
* @param $columns string The (comma separated) columns that should be retrieved from the database.
105+
* Is being translated directly into the `.sql`.
106+
* @param $callback Closure A callback that defines how the retrieved columns are processed.
107+
* @param $params Array Optional additional parameters that are passed to the given Closure.
108+
* @param $callbackName string Optional string that defines the 'name' of the column.
109+
* Leave empty to let livewire autogenerate a distinct value.
110+
*/
111+
public static function callback(
112+
string $columns,
113+
Closure $callback,
114+
array $params = [],
115+
?string $callbackName = null
116+
) {
102117
$column = new static;
103118

104-
$column->name = 'callback_' . crc32(json_encode(func_get_args()));
119+
$column->name = 'callback_' . ($callbackName ?? crc32(json_encode(func_get_args())));
105120
$column->callback = $callback;
106121
$column->additionalSelects = is_array($columns) ? $columns : array_map('trim', explode(',', $columns));
107122
$column->params = $params;

0 commit comments

Comments
 (0)