diff --git a/src/Chumper/Datatable/Table.php b/src/Chumper/Datatable/Table.php index 3b114ff..9083047 100644 --- a/src/Chumper/Datatable/Table.php +++ b/src/Chumper/Datatable/Table.php @@ -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), @@ -325,7 +325,7 @@ public function noScript() return $this; } - private function convertData($options) { + private function convertData($options, $callbacks = []) { $is_obj = false; $first = true; $data = ""; @@ -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) { @@ -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, )); }