Skip to content

Commit

Permalink
Add utility functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Dec 1, 2022
1 parent 7c8660b commit 47ca819
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/source/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ $table->add('buttons', TwigColumn::class, [
This column type allows you to specify a Twig template used to render the column's cells. The
template is rendered using the main application context by injecting the main Twig service.
Additionally the `value` and `row` parameters are being filled by the cell value and the row
level context respectively.
level context respectively, and the `column` parameter contains the column class itself.

Option | Type | Description
------ | ---- | -----------
Expand All @@ -503,7 +503,7 @@ $table->add('link', TwigStringColumn::class, [
This column type allows you to inline a Twig template as a string used to render the column's cells. The
template is rendered using the main application context by injecting the main Twig service.
Additionally, the `value` and `row` parameters are being filled by the cell value and the row
level context respectively.
level context respectively, and the `column` parameter contains the column class itself.

This column type requires `StringLoaderExtension` to be [enabled in your Twig environment](https://symfony.com/doc/4.4/reference/dic_tags.html#twig-extension).

Expand Down
10 changes: 8 additions & 2 deletions src/Column/AbstractColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Omines\DataTablesBundle\Column;

use Omines\DataTablesBundle\DataTable;
use Omines\DataTablesBundle\DataTableState;
use Omines\DataTablesBundle\Filter\AbstractFilter;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand Down Expand Up @@ -63,7 +64,7 @@ public function transform($value = null, $context = null)
{
$data = $this->getData();
if (is_callable($data)) {
$value = call_user_func($data, $context, $value);
$value = call_user_func($data, $context, $value, $this);
} elseif (null === $value) {
$value = $data;
}
Expand All @@ -83,7 +84,7 @@ protected function render($value, $context)
if (is_string($render = $this->options['render'])) {
return sprintf($render, $value);
} elseif (is_callable($render)) {
return call_user_func($render, $value, $context);
return call_user_func($render, $value, $context, $this);
}

return $value;
Expand Down Expand Up @@ -271,6 +272,11 @@ public function getDataTable(): DataTable
return $this->dataTable;
}

public function getState(): DataTableState
{
return $this->dataTable->getState();
}

/**
* @param mixed $value
* @return $this
Expand Down
1 change: 1 addition & 0 deletions src/Column/TwigColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected function render($value, $context)
return $this->twig->render($this->getTemplate(), [
'row' => $context,
'value' => $value,
'column' => $this,
]);
}

Expand Down
1 change: 1 addition & 0 deletions src/Column/TwigStringColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(Environment $twig = null)
protected function render($value, $context)
{
return $this->twig->render('@DataTables/Column/twig_string.html.twig', [
'column' => $this,
'column_template' => $this->getTemplate(),
'row' => $context,
'value' => $value,
Expand Down
5 changes: 5 additions & 0 deletions src/DataTableState.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,9 @@ public function getExporterName(): ?string
{
return $this->exporterName;
}

public function isExport(): bool
{
return null !== $this->exporterName;
}
}

0 comments on commit 47ca819

Please sign in to comment.