File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -190,6 +190,9 @@ $datatables->addOrderEscapes([
190190
191191// Don't forget to call generate to get the results
192192$datatables->generate();
193+
194+ // Optional usage: get the response data as an array instead of sending JSON
195+ $data = $datatables->generate(true);
193196```
194197
195198## Complete Example
Original file line number Diff line number Diff line change @@ -342,9 +342,15 @@ public function asObject()
342342 }
343343
344344 /**
345- * Generate the datatables results
345+ * Generate DataTables results.
346+ *
347+ * By default, sends JSON response and exits.
348+ * If $return = true, returns the response data as an array instead.
349+ *
350+ * @param bool $return Optional. Return array instead of sending JSON. Default: false.
351+ * @return array|null Response array if $return = true, otherwise null.
346352 */
347- public function generate ()
353+ public function generate ($ return = FALSE )
348354 {
349355 $ this ->setReturnedFieldNames ();
350356 $ this ->filter ();
@@ -380,13 +386,19 @@ public function generate()
380386 }
381387 }
382388
383- $ response = new JsonResponse ();
384- $ response ->setData ([
389+ $ responseData = [
385390 'draw ' => $ this ->request ->get ('draw ' ),
386391 'recordsTotal ' => $ this ->recordsTotal ,
387392 'recordsFiltered ' => $ this ->recordsFiltered ,
388393 'data ' => $ output
389- ]);
394+ ];
395+
396+ if ($ return ) {
397+ return $ responseData ;
398+ }
399+
400+ $ response = new JsonResponse ();
401+ $ response ->setData ($ responseData );
390402 $ response ->send ();
391403 exit ;
392404 }
You can’t perform that action at this time.
0 commit comments