|
19 | 19 | use Omines\DataTablesBundle\Exception\InvalidArgumentException; |
20 | 20 | use Omines\DataTablesBundle\Exception\InvalidConfigurationException; |
21 | 21 | use Omines\DataTablesBundle\Exception\InvalidStateException; |
| 22 | +use Omines\DataTablesBundle\Exporter\DataTableExporterManager; |
22 | 23 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
23 | 24 | use Symfony\Component\HttpFoundation\JsonResponse; |
24 | 25 | use Symfony\Component\HttpFoundation\Request; |
| 26 | +use Symfony\Component\HttpFoundation\Response; |
25 | 27 | use Symfony\Component\OptionsResolver\OptionsResolver; |
26 | 28 |
|
27 | 29 | /** |
@@ -69,6 +71,9 @@ class DataTable |
69 | 71 | /** @var EventDispatcherInterface */ |
70 | 72 | protected $eventDispatcher; |
71 | 73 |
|
| 74 | + /** @var DataTableExporterManager */ |
| 75 | + protected $exporterManager; |
| 76 | + |
72 | 77 | /** @var string */ |
73 | 78 | protected $method = Request::METHOD_POST; |
74 | 79 |
|
@@ -107,10 +112,16 @@ class DataTable |
107 | 112 |
|
108 | 113 | /** |
109 | 114 | * DataTable constructor. |
| 115 | + * |
| 116 | + * @param EventDispatcherInterface $eventDispatcher |
| 117 | + * @param DataTableExporterManager $exporterManager |
| 118 | + * @param array $options |
| 119 | + * @param Instantiator|null $instantiator |
110 | 120 | */ |
111 | | - public function __construct(EventDispatcherInterface $eventDispatcher, array $options = [], Instantiator $instantiator = null) |
| 121 | + public function __construct(EventDispatcherInterface $eventDispatcher, DataTableExporterManager $exporterManager, array $options = [], Instantiator $instantiator = null) |
112 | 122 | { |
113 | 123 | $this->eventDispatcher = $eventDispatcher; |
| 124 | + $this->exporterManager = $exporterManager; |
114 | 125 |
|
115 | 126 | $this->instantiator = $instantiator ?? new Instantiator(); |
116 | 127 |
|
@@ -277,12 +288,20 @@ public function handleRequest(Request $request): self |
277 | 288 | return $this; |
278 | 289 | } |
279 | 290 |
|
280 | | - public function getResponse(): JsonResponse |
| 291 | + public function getResponse(): Response |
281 | 292 | { |
282 | 293 | if (null === $this->state) { |
283 | 294 | throw new InvalidStateException('The DataTable does not know its state yet, did you call handleRequest?'); |
284 | 295 | } |
285 | 296 |
|
| 297 | + // Server side export |
| 298 | + if (null !== $this->state->getExporterName()) { |
| 299 | + return $this->exporterManager |
| 300 | + ->setDataTable($this) |
| 301 | + ->setExporterName($this->state->getExporterName()) |
| 302 | + ->getResponse(); |
| 303 | + } |
| 304 | + |
286 | 305 | $resultSet = $this->getResultSet(); |
287 | 306 | $response = [ |
288 | 307 | 'draw' => $this->state->getDraw(), |
|
0 commit comments