Skip to content

Commit 7205552

Browse files
committed
Keep fields order when using 'only' method
1 parent 3aae85c commit 7205552

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/DataTables.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ public function except($columns)
121121
protected function setReturnedFieldNames()
122122
{
123123
if ( ! empty($this->only)) {
124-
foreach ($this->fieldNames as $field) {
125-
if (in_array($field, $this->only)) {
124+
// Keep fields order as defined
125+
foreach ($this->only as $field) {
126+
if (in_array($field, $this->fieldNames)) {
126127
array_push($this->returnedFieldNames, $field);
127128
}
128129
}

0 commit comments

Comments
 (0)