/** * Will sort the query based on the given datatable query configuration. */ private function sortQuery() { if ($this->queryConfiguration->hasOrderColumn()) { $orderColumns = $this->queryConfiguration->orderColumns(); foreach ($orderColumns as $order) { $this->query->orderBy($order->columnName(), $order->isDescending() ? 'desc' : 'asc'); } } }
/** * Will sort the internal collection based on the given query configuration. * Most tables only support the ordering by just one column, but we will enable sorting on all columns here */ private function sortCollection() { if ($this->queryConfiguration->hasOrderColumn()) { $order = $this->queryConfiguration->orderColumns(); $orderFunc = $this->defaultGlobalOrderFunction; $this->collection = $this->collection->sort(function ($first, $second) use($order, $orderFunc) { return $orderFunc($first, $second, $order); }); } }
/** * Will sort the internal collection based on the given query configuration. * All tables only support the ordering by just one column, so if there is ordering just take the first ordering */ private function sortCollection() { if ($this->queryConfiguration->hasOrderColumn()) { $order = $this->queryConfiguration->orderColumns()[0]; $this->collection->sort(function ($first, $second) use($order) { return strnatcmp($first[$order->columnName()], $second[$order->columnName()]); }); if (!$order->isAscending()) { $this->collection->reverse(); } } }