Skip to content

Commit 47ca819

Browse files
committed
Add utility functionality
1 parent 7c8660b commit 47ca819

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

docs/source/index.html.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ $table->add('buttons', TwigColumn::class, [
484484
This column type allows you to specify a Twig template used to render the column's cells. The
485485
template is rendered using the main application context by injecting the main Twig service.
486486
Additionally the `value` and `row` parameters are being filled by the cell value and the row
487-
level context respectively.
487+
level context respectively, and the `column` parameter contains the column class itself.
488488

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

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

src/Column/AbstractColumn.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Omines\DataTablesBundle\Column;
1414

1515
use Omines\DataTablesBundle\DataTable;
16+
use Omines\DataTablesBundle\DataTableState;
1617
use Omines\DataTablesBundle\Filter\AbstractFilter;
1718
use Symfony\Component\OptionsResolver\OptionsResolver;
1819

@@ -63,7 +64,7 @@ public function transform($value = null, $context = null)
6364
{
6465
$data = $this->getData();
6566
if (is_callable($data)) {
66-
$value = call_user_func($data, $context, $value);
67+
$value = call_user_func($data, $context, $value, $this);
6768
} elseif (null === $value) {
6869
$value = $data;
6970
}
@@ -83,7 +84,7 @@ protected function render($value, $context)
8384
if (is_string($render = $this->options['render'])) {
8485
return sprintf($render, $value);
8586
} elseif (is_callable($render)) {
86-
return call_user_func($render, $value, $context);
87+
return call_user_func($render, $value, $context, $this);
8788
}
8889

8990
return $value;
@@ -271,6 +272,11 @@ public function getDataTable(): DataTable
271272
return $this->dataTable;
272273
}
273274

275+
public function getState(): DataTableState
276+
{
277+
return $this->dataTable->getState();
278+
}
279+
274280
/**
275281
* @param mixed $value
276282
* @return $this

src/Column/TwigColumn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ protected function render($value, $context)
4444
return $this->twig->render($this->getTemplate(), [
4545
'row' => $context,
4646
'value' => $value,
47+
'column' => $this,
4748
]);
4849
}
4950

src/Column/TwigStringColumn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function __construct(Environment $twig = null)
3838
protected function render($value, $context)
3939
{
4040
return $this->twig->render('@DataTables/Column/twig_string.html.twig', [
41+
'column' => $this,
4142
'column_template' => $this->getTemplate(),
4243
'row' => $context,
4344
'value' => $value,

src/DataTableState.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,9 @@ public function getExporterName(): ?string
228228
{
229229
return $this->exporterName;
230230
}
231+
232+
public function isExport(): bool
233+
{
234+
return null !== $this->exporterName;
235+
}
231236
}

0 commit comments

Comments
 (0)