Skip to content

Commit 885a095

Browse files
committed
Fix DT_Row options when returning a flatten array response.
Fix PR #126
1 parent f1b8dd2 commit 885a095

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/yajra/Datatables/Processors/DataProcessor.php

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

33
namespace yajra\Datatables\Processors;
44

5-
use Illuminate\Support\Arr;
65
use yajra\Datatables\Helper;
76

87
/**
@@ -73,12 +72,9 @@ public function process($object = false)
7372
$value = $this->addColumns($data, $row);
7473
$value = $this->editColumns($value, $row);
7574
$value = $this->setupRowVariables($value, $row);
76-
if ( ! $object) {
77-
$value = Arr::flatten($this->removeExcessColumns($value));
78-
} else {
79-
$value = $this->removeExcessColumns($value);
80-
}
81-
$this->output[] = $value;
75+
$value = $this->removeExcessColumns($value);
76+
77+
$this->output[] = $object ? $value : $this->flatten($value);
8278
}
8379

8480
return $this->output;
@@ -152,4 +148,25 @@ protected function removeExcessColumns(array $data)
152148
return $data;
153149
}
154150

151+
/**
152+
* Flatten array with exceptions.
153+
*
154+
* @param array $array
155+
* @return array
156+
*/
157+
public function flatten(array $array)
158+
{
159+
$return = [];
160+
$exceptions = ['DT_RowId', 'DT_RowClass', 'DT_RowData', 'DT_RowAttr'];
161+
162+
foreach ($array as $key => $value) {
163+
if (in_array($key, $exceptions)) {
164+
$return[$key] = $value;
165+
} else {
166+
$return[] = $value;
167+
}
168+
}
169+
170+
return $return;
171+
}
155172
}

0 commit comments

Comments
 (0)