Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Fix for issue #338 #348

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
30 changes: 24 additions & 6 deletions src/Chumper/Datatable/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function getViewParameters()
$this->createMapping();
}
return array(
'options' => $this->convertData(array_merge($this->options, $this->callbacks)),
'options' => $this->convertData($this->options, $this->callbacks),
'values' => $this->customValues,
'data' => $this->data,
'columns' => array_combine($this->aliasColumns,$this->columns),
Expand All @@ -325,7 +325,7 @@ public function noScript()
return $this;
}

private function convertData($options) {
private function convertData($options, $callbacks = []) {
$is_obj = false;
$first = true;
$data = "";
Expand All @@ -342,18 +342,36 @@ private function convertData($options) {
$data .= json_encode($k) . ":";
}
if (is_string($o)) {
if (@preg_match("#^\s*function\s*\([^\)]*#", $o)) {
$data .= $o;
$data .= json_encode($o);
} else {
if (is_array($o)) {
$data .= $this->convertData($o);
} else {
$data .= json_encode($o);
}
}
}

foreach($callbacks as $k => $o){
if ($first == true) {
if (!is_numeric($k)) {
$is_obj = true;
}
$first = false;
} else {
$data .= ",\n";
}
$data .= json_encode($k) . ":";
if (is_string($o)) {
$data .= $o;
} else {
if (is_array($o)) {
$data .= $this->convertData($o);
$data .= $this->convertData([],$o);
} else {
$data .= json_encode($o);
}
}

}

if ($is_obj) {
Expand All @@ -377,7 +395,7 @@ public function script($view = null)
}

return View::make($this->script_view,array(
'options' => $this->convertData(array_merge($this->options, $this->callbacks)),
'options' => $this->convertData($this->options, $this->callbacks),
'id' => $this->idName,
));
}
Expand Down