Skip to content

Commit

Permalink
Revert "feat: add "header_row_attr" and "value_row_attr" options, dep…
Browse files Browse the repository at this point in the history
…recate related getters and setters"

This reverts commit 65397f1.
  • Loading branch information
Kreyu committed Oct 4, 2024
1 parent 65397f1 commit 2d859b6
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 108 deletions.
62 changes: 0 additions & 62 deletions docs/src/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,65 +131,3 @@ Now, in the template, render the data table using the `data_table` function:
```

By default, the data table will look somewhat _ugly_, because we haven't configured the theme yet - see [theming](features/theming.md) documentation section.

## Setting data table title

The data tables can have a title set, that in built-in themes is displayed on the left side of the card header:

```php
namespace App\DataTable\Type;

use App\Entity\Product;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ProductDataTableType extends AbstractDataTableType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'title' => 'Products',
]);
}
}
```

For more flexibility, you can set the title directly in the Twig, while rendering the data table:

```twig
{# templates/product/index.html.twig #}
<div class="card">
{{ data_table(products, { title: 'Products' }) }}
</div>
```

## Setting row attributes

Both header and value rows HTML attributes can be provided by the `header_row_attr` and `value_row_attr`.
The `value_row_attr` accepts a callable, that retrieves data of the row:

```php
namespace App\DataTable\Type;

use App\Entity\Product;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ProductDataTableType extends AbstractDataTableType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'header_row_attr' => [
'class' => 'bg-primary',
],
'value_row_attr' => function (Product $product): array {
return [
'class' => $product->isOutOfStock() ? 'bg-danger' : '',
];
}
]);
}
}
```
12 changes: 0 additions & 12 deletions src/DataTableConfigBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,12 @@ public function setAttribute(string $name, mixed $value): static;

public function setAttributes(array $attributes): static;

/**
* @deprecated use "header_row_attr" option instead
*/
public function setHeaderRowAttribute(string $name, mixed $value): static;

/**
* @deprecated use "header_row_attr" option instead
*/
public function setHeaderRowAttributes(array $headerRowAttributes): static;

/**
* @deprecated use "value_row_attr" option instead
*/
public function setValueRowAttribute(string $name, mixed $value): static;

/**
* @deprecated use "value_row_attr" option instead
*/
public function setValueRowAttributes(array $valueRowAttributes): static;

public function getDataTableConfig(): DataTableConfigInterface;
Expand Down
18 changes: 0 additions & 18 deletions src/DataTableConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,34 +109,16 @@ public function hasAttribute(string $name): bool;

public function getAttribute(string $name, mixed $default = null): mixed;

/**
* @deprecated use "header_row_attr" option instead
*/
public function getHeaderRowAttributes(): array;

/**
* @deprecated use "header_row_attr" option instead
*/
public function hasHeaderRowAttribute(string $name): bool;

/**
* @deprecated use "header_row_attr" option instead
*/
public function getHeaderRowAttribute(string $name, mixed $default = null): mixed;

/**
* @deprecated use "value_row_attr" option instead
*/
public function getValueRowAttributes(): array;

/**
* @deprecated use "value_row_attr" option instead
*/
public function hasValueRowAttribute(string $name): bool;

/**
* @deprecated use "value_row_attr" option instead
*/
public function getValueRowAttribute(string $name, mixed $default = null): mixed;

public function getPageParameterName(): string;
Expand Down
16 changes: 0 additions & 16 deletions src/Type/DataTableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,6 @@ private function createHeaderRowView(DataTableView $view, DataTableInterface $da
$headerRowView->vars['attr'][$key] = $value;
}

$attr = $dataTable->getConfig()->getOption('header_row_attr', []);

foreach ($attr as $key => $value) {
$headerRowView->vars['attr'][$key] = $value;
}

foreach ($columns as $column) {
$headerRowView->children[$column->getName()] = $column->createHeaderView($headerRowView);
}
Expand Down Expand Up @@ -320,16 +314,6 @@ private function createValueRowsViews(DataTableView $view, DataTableInterface $d
$valueRowView->vars['attr'][$key] = $value;
}

$attr = $dataTable->getConfig()->getOption('value_row_attr', []);

if (is_callable($attr)) {
$attr = $attr($data, $dataTable);
}

foreach ($attr as $key => $value) {
$valueRowView->vars['attr'][$key] = $value;
}

foreach ($columns as $column) {
$valueRowView->children[$column->getName()] = $column->createValueView($valueRowView);
}
Expand Down

0 comments on commit 2d859b6

Please sign in to comment.