1616use Omines \DataTablesBundle \Adapter \ResultSetInterface ;
1717use Omines \DataTablesBundle \Column \AbstractColumn ;
1818use Omines \DataTablesBundle \DependencyInjection \Instantiator ;
19+ use Omines \DataTablesBundle \Event \DataTablePostResponseEvent ;
20+ use Omines \DataTablesBundle \Event \DataTablePreResponseEvent ;
1921use Omines \DataTablesBundle \Exception \InvalidArgumentException ;
2022use Omines \DataTablesBundle \Exception \InvalidConfigurationException ;
2123use Omines \DataTablesBundle \Exception \InvalidStateException ;
@@ -123,6 +125,28 @@ public function add(string $name, string $type, array $options = []): static
123125 return $ this ;
124126 }
125127
128+ public function remove (string $ name ): static
129+ {
130+ if (!isset ($ this ->columnsByName [$ name ])) {
131+ throw new InvalidArgumentException (sprintf ("There is no column with name '%s' " , $ name ));
132+ }
133+
134+ $ column = $ this ->columnsByName [$ name ];
135+ unset($ this ->columnsByName [$ name ]);
136+ $ index = array_search ($ column , $ this ->columns , true );
137+ unset($ this ->columns [$ index ]);
138+
139+ return $ this ;
140+ }
141+
142+ public function clearColumns (): static
143+ {
144+ $ this ->columns = [];
145+ $ this ->columnsByName = [];
146+
147+ return $ this ;
148+ }
149+
126150 /**
127151 * Adds an event listener to an event on this DataTable.
128152 *
@@ -263,14 +287,19 @@ public function handleRequest(Request $request): static
263287
264288 public function getResponse (): Response
265289 {
290+ $ this ->eventDispatcher ->dispatch (new DataTablePreResponseEvent ($ this ), DataTableEvents::PRE_RESPONSE );
291+
266292 $ state = $ this ->getState ();
267293
268294 // Server side export
269295 if (null !== $ state ->getExporterName ()) {
270- return $ this ->exporterManager
296+ $ response = $ this ->exporterManager
271297 ->setDataTable ($ this )
272298 ->setExporterName ($ state ->getExporterName ())
273299 ->getResponse ();
300+ $ this ->eventDispatcher ->dispatch (new DataTablePostResponseEvent ($ this ), DataTableEvents::POST_RESPONSE );
301+
302+ return $ response ;
274303 }
275304
276305 $ resultSet = $ this ->getResultSet ();
@@ -285,6 +314,8 @@ public function getResponse(): Response
285314 $ response ['template ' ] = $ this ->renderer ->renderDataTable ($ this , $ this ->template , $ this ->templateParams );
286315 }
287316
317+ $ this ->eventDispatcher ->dispatch (new DataTablePostResponseEvent ($ this ), DataTableEvents::POST_RESPONSE );
318+
288319 return new JsonResponse ($ response );
289320 }
290321
0 commit comments