Skip to content

Commit 75c773c

Browse files
committed
Implement buttons support for editor.
As per PR yajra/laravel-datatables#1105.
1 parent 385f66b commit 75c773c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Html/Builder.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public function parameterize($attributes = [])
172172
list($ajaxDataFunction, $parameters) = $this->encodeAjaxDataFunction($parameters);
173173
list($columnFunctions, $parameters) = $this->encodeColumnFunctions($parameters);
174174
list($callbackFunctions, $parameters) = $this->encodeCallbackFunctions($parameters);
175+
list($editorButtons, $parameters) = $this->encodeEditorButtons($parameters);
175176

176177
$json = json_encode($parameters);
177178

@@ -180,10 +181,47 @@ public function parameterize($attributes = [])
180181
$json = $this->decodeAjaxDataFunction($ajaxDataFunction, $json);
181182
$json = $this->decodeColumnFunctions($columnFunctions, $json);
182183
$json = $this->decodeCallbackFunctions($callbackFunctions, $json);
184+
$json = $this->decodeEditorButtons($editorButtons, $json);
183185

184186
return $json;
185187
}
186188

189+
190+
/**
191+
* Encode DataTables editor buttons.
192+
*
193+
* @param array $parameters
194+
* @return array
195+
*/
196+
protected function encodeEditorButtons(array $parameters)
197+
{
198+
$editorButtons = [];
199+
if (isset($parameters['buttons'])) {
200+
foreach ($parameters['buttons'] as $i => $button) {
201+
if (isset($button['editor'])) {
202+
$editorButtons[$i] = $this->compileCallback($button['editor']);
203+
$parameters['buttons'][$i]['editor'] = "#editor_button.{$i}#";
204+
}
205+
}
206+
}
207+
return [$editorButtons, $parameters];
208+
}
209+
210+
/**
211+
* Decode DataTables Editor buttons.
212+
*
213+
* @param array $editorButtons
214+
* @param string $json
215+
* @return string
216+
*/
217+
protected function decodeEditorButtons(array $editorButtons, $json)
218+
{
219+
foreach ($editorButtons as $i => $function) {
220+
$json = str_replace("\"#editor_button.{$i}#\"", $function, $json);
221+
}
222+
return $json;
223+
}
224+
187225
/**
188226
* Get table computed table attributes.
189227
*

0 commit comments

Comments
 (0)