OpenSkill\Datatable\Composers\ColumnComposer::column PHP Метод

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

Will create a new ColumnConfiguration with all defaults but allows overriding of all properties through the method.
public column ( string $name, string | callable $callable = null, Searchable $searchable = null, OpenSkill\Datatable\Columns\Orderable\Orderable $orderable = null )
$name string The name of the configuration, required for the configuration
$callable string | callable The function to execute, defaults to null which means the default will be set.
$searchable OpenSkill\Datatable\Columns\Searchable\Searchable If the column should be searchable or not
$orderable OpenSkill\Datatable\Columns\Orderable\Orderable If the column should be orderable or not
    public function column($name, $callable = null, Searchable $searchable = null, Orderable $orderable = null)
    {
        /**
         * @var ColumnConfigurationBuilder
         */
        $config = ColumnConfigurationBuilder::create();
        if (is_string($name)) {
            $config->name($name);
        } else {
            throw new \InvalidArgumentException('$name must be a string');
        }
        if (!is_null($callable)) {
            $this->setCallableColumn($config, $callable);
        }
        if (is_null($searchable)) {
            $config->searchable(Searchable::NORMAL());
        }
        if (is_null($orderable)) {
            $config->orderable(Orderable::BOTH());
        }
        $this->columnConfiguration[] = $config->build();
        return $this;
    }

Usage Example

 /**
  * Will check if the column method with a string works
  */
 public function testNameCallableColumn()
 {
     $name = "fooBar";
     $this->composer->column($name, $name);
     // get configuration and verify
     $numberOfColumns = count($this->composer->getColumnConfiguration());
     $this->assertSame($numberOfColumns, 1, "There should only be one column configuration");
     /**
      * @var ColumnConfiguration
      */
     $cc = $this->composer->getColumnConfiguration()[0];
     /**
      * @var callable
      */
     $func = $cc->getCallable();
     $this->assertTrue($cc->getOrder()->isOrderable(), "The column should be orderable");
     $this->assertTrue($cc->getSearch()->isSearchable(), "The column should be searchable");
     $this->assertSame($name, $cc->getName(), "The name should be set to 'fooBar'");
     $this->assertSame($name, $func($name));
 }