OpenSkill\Datatable\Providers\CollectionProvider::order PHP Метод

order() публичный Метод

Will accept a global search function for all columns.
public order ( callable $orderFunction )
$orderFunction callable the order function to determine the order of the table
    public function order(callable $orderFunction)
    {
        $this->defaultGlobalOrderFunction = $orderFunction;
        return $this;
    }

Usage Example

 public function testCustomOrder()
 {
     $data = [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']];
     $queryConfiguration = QueryConfigurationBuilder::create()->start(0)->length(2)->drawCall(1)->columnOrder('id', 'desc')->build();
     $columnConfiguration = ColumnConfigurationBuilder::create()->name('id')->build();
     $provider = new CollectionProvider(new Collection($data));
     $provider->order(function ($first, $second, array $order) {
         if (!$order[0]->isAscending()) {
             return $first['id'] < $second['id'] ? 1 : ($first['id'] > $second['id'] ? -1 : 0);
         }
         return $first['id'] < $second['id'] ? -1 : ($first['id'] > $second['id'] ? 1 : 0);
     });
     $provider->prepareForProcessing($queryConfiguration, [$columnConfiguration]);
     $data = $provider->process();
     $this->assertSame(2, $data->data()->count());
     $first = $data->data()->first();
     $this->assertSame(2, $first['id']);
 }