Rendering via 'return' function / server side processing Datatables / Typo3 / PHP
Rendering via 'return' function / server side processing Datatables / Typo3 / PHP
Dear Datatables Team,
how do I need to adjust the 'Output' of https://datatables.net/development/server-side/php_mysql for the JSON array / or the output in general to be rendered via the 'return' function? Typo3 requires rendering via 'return' (http://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/UserAndUserInt/Index.html).
```
<?php
class my_custom_datatable {
var $datatable; // ** reference to the calling object. **//
function my_custom_table1($my_output) {
global $TSFE;
$TSFE->set_no_cache();
// ** datatable script can go here **//
return $my_output; // ** Typo3 requires rendering via 'return' (http://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/UserAndUserInt/Index.html). **//
}
}
<?php > ``` Unfortunately I can't use "echo json_encode( $output );" as in the example. When using "echo json_encode( $output );" all data (valid JSON string) is rendered at the very top of the page outside of the html tags and not in the table. I also raised the question here: http://stackoverflow.com/questions/29242553/json-array-rendered-via-return-function-php-datatables-typo3 ?>Thanks for the help!
This question has accepted answers - jump to:
Answers
Happy Easter Everyone!
Unfortunately I'm still having trouble to render the data into the table. Please take a look at the example here:
http://www.rfpfactsheet.com/
As mentioned above, I'm trying to include https://datatables.net/development/server-side/php_mysql into Typo3. Including a php script into Typo3 requires the above structure though and rendering the data via the return function.
I'm using the php script as in the example:
<html>
<body>
</html>
```
Any help would be much appreciated! After all, its Easter! :-)
My code is properly returning the data server side so try to use that to help you out. I use laravel framework so some of it will have to be changed...
For example where you see " {{ code here }} " is really <?php echo 'code here' ?> but you should be able to figure it out.
https://www.datatables.net/forums/discussion/27017/filtered-data#latest
Thanks for your example farr433. Obviously I'm new to php and I'm struggling to get it running. Any additional help/hint would be much appreciated!
Did you ask the Typo3 people? They have a plug-in which facilitates DataTables.
Thanks tangerine. I have the http://typo3.org/extensions/repository/view/cag_tables extension running, but unfortunately it's not serverside processing. My data load is to big (>50000 rows) and I have a performance issue, that's why I would like to have the serverside processing ...
In meantime I managed to render the data at the right place. The trick was I changed the rendering to ...
return json_encode( $output );
... and the data is now rendered at the marker, but unfortunately still not in the table. CRY. Live example (incl. syntax showcase):
http://www.rfpfactsheet.com/rfp-issuer/a001-finance-factsheet/rfp-id-a001/live-example/
Syntax used:
Error message:
"Invalid JSON response" although jsonlint.com says it's valid. CRY again
I also activated the caching again, but deleted // var $field_datatable;
But why is the data still not in the table?
Doesn't look like JSON to me:
Looks like HTML :-). In fact it looks like the same page again.
Allan
Hi Allan! What do I need to do?! :-)
... php is rendering the following:
{"sEcho":0,"iTotalRecords":"6","iTotalDisplayRecords":"6","aaData":[["1","Hans","Meier","51","2011-04-13","EUR200"],["2","Frank","Heinz","45","2004-02-17","EUR60"],["3","Katrin","Kohl","35","2011-08-17","EUR1000"],["4","Werner","Pertl","39","2013-11-19","USD499"],["5","Christina","Sinn","22","2015-03-09","GBP99"],["6","Klaus","Vienna","67","1991-01-15","EUR5000"]]}
... and per www.jsonlint.com it's a "Valid JSON".
In the data source of http://www.rfpfactsheet.com/rfp-issuer/a001-finance-factsheet/rfp-id-a001/live-example/ you see the output on line 166 right next to the "ajax" call.
I used a ###TYPO3 MARKER### to get the php return there. I used...
return json_encode( $output );
In other posts I saw that "sEcho":0 shouldn't be the case. Is the php script I'm using not compatible with the libraries I'm using?
.../jquery-1.11.1.min.js
.../jqueryui/1/jquery-ui.min.js
.../1.10.5/js/jquery.dataTables.min.js
.../1.10.5/css/jquery.dataTables.css
What PHP is rendering that data?
Hmm, I've just taken a look at your initialisation of the table and it looks wrong:
You haven't specified a url for where it should get the data (see
ajax
).I don't understand why you have put
sEcho
, etc, into theajax
object. Could you tell me where you found that in the documentation so I can correct it - it is wrong.I would suggest reading over the server-side processing manual.
I would also highlight that unless you have 50k+ rows, you are unlikely to need server-side processing.
Allan
I'm using the php script found here: https://datatables.net/development/server-side/php_mysql Then I embedded the php script in the following structure (required by TYPO3) ...
```
<?php
class custom_datatable {
}
<?php > ``` ?>}
and 'return' the php action to the ###TYPO3 MARKER### in the javascript syntax (which I put/defined next to the 'ajax' call). The thing with the url is, that https://typo3.org/ doesn't allow me to include .php files directly in the html/javascript (eg via a defined path to the php script), due to security. It needs to go indirectly via a defined ###TYPO3 MARKER###. But I can place the marker in html/javascript anywhere I want. The marker then will be replaced by whatever the php returns back. In our case the array.
Reading through the manual, maybe in my case it's an issue with 'ajax'. Since the ###TYPO3 MARKER### maybe only listens to the php script and not to the 'ajax' call.
I really want the server side processing since I have easily 50k+ rows and even more. I'm already using DOM, but it is too slow and the browser freezes.
You want your DataTables initialisation to look something like this:
Note that the
ajax
option is a string which points to a URL that can be loaded by Ajax. You can see an example of that here.I would also suggest using the new style SSP class rather than the legacy script you found above. Click on the "Server-side script" tab below the table in the example I linked to above to see how it is configured.
Key point: If you are using server-side processing, you do not want to embed the results into the page directly. You want to get the results via Ajax.
Allan
Hi Allan! I now have it running. What I needed to do in TYPO3 is to output the json array via the typNum function in a TYPO3 extension, similar to the post here: http://stackoverflow.com/questions/27925797/typo3-extbase-json-output. And finally define the typNum link (in my case "/index.php?id=45&type=5001" as the source of the json array. So it looks like e.g.
Excellent - good to hear you got it going. Thanks for posting back with your findings.
Allan