diff --git a/docs/src/docs/usage.md b/docs/src/docs/usage.md index 75a38104..8c9739e8 100644 --- a/docs/src/docs/usage.md +++ b/docs/src/docs/usage.md @@ -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 #} - -
- {{ data_table(products, { title: 'Products' }) }} -
-``` - -## 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' : '', - ]; - } - ]); - } -} -``` diff --git a/src/DataTableConfigBuilderInterface.php b/src/DataTableConfigBuilderInterface.php index 03959712..7569ba2a 100755 --- a/src/DataTableConfigBuilderInterface.php +++ b/src/DataTableConfigBuilderInterface.php @@ -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; diff --git a/src/DataTableConfigInterface.php b/src/DataTableConfigInterface.php index 7eb1332f..3a98b8c9 100755 --- a/src/DataTableConfigInterface.php +++ b/src/DataTableConfigInterface.php @@ -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; diff --git a/src/Type/DataTableType.php b/src/Type/DataTableType.php index 6bdba104..7795f002 100755 --- a/src/Type/DataTableType.php +++ b/src/Type/DataTableType.php @@ -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); } @@ -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); }