OpenSkill\Datatable\Providers\CollectionProvider::process PHP Method

process() public method

It will be called after {@link #prepareForProcessing} has been called and needs to return the processed data in a DTData object so the Composer can further handle the data.
public process ( ) : ResponseData
return OpenSkill\Datatable\Data\ResponseData The processed data
    public function process()
    {
        // check if the query configuration is set
        if (is_null($this->queryConfiguration) || empty($this->columnConfiguration)) {
            throw new \InvalidArgumentException("Provider was not configured. Did you call prepareForProcessing first?");
        }
        // compile the collection first
        $this->compileCollection($this->columnConfiguration);
        // sort
        $this->sortCollection();
        // slice the result into the right size
        return new ResponseData($this->collection->slice($this->queryConfiguration->start(), $this->queryConfiguration->length()), $this->totalInitialDataCount);
    }

Usage Example

 public function testDefaultOrderMulti()
 {
     $data = [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar'], ['id' => 3, 'name' => 'foo'], ['id' => 4, 'name' => 'bar']];
     $queryConfiguration = QueryConfigurationBuilder::create()->start(0)->length(4)->drawCall(1)->columnOrder('name', 'asc')->columnOrder('id', 'desc')->build();
     $columnConfiguration = ColumnConfigurationBuilder::create()->name('id')->build();
     $columnConfiguration2 = ColumnConfigurationBuilder::create()->name('name')->build();
     $provider = new CollectionProvider(new Collection($data));
     $provider->prepareForProcessing($queryConfiguration, [$columnConfiguration, $columnConfiguration2]);
     $data = $provider->process();
     $this->assertSame(4, $data->data()->count());
     $first = $data->data()->first();
     $second = $data->data()->get(1);
     $this->assertSame(4, $first['id']);
     $this->assertSame(2, $second['id']);
 }
All Usage Examples Of OpenSkill\Datatable\Providers\CollectionProvider::process