Custom Output in Table with Server-side processing
Custom Output in Table with Server-side processing
Hello Forum,
im using datatables for about 6 months. In this time the amount of tables rows grows very fast.
I load the datas with a SQL query an put it out directly in the table and format it with js.
Now the table becomes realy slow. So i tried Server-side processing. The basic works, its very fast now. I use this example:
https://www.datatables.net/examples/data_sources/server_side.html
The script works. But i need more customization.
In my normal output i put some styling an additional information in each cell.
For example:
<td data-html=\"true\" class=\" popovers\" data-container=\"body\" data-trigger=\"hover\" data-placement=\"top\" data-content=\"Bericht $value<br />betrachten\" data-original-title=\"BERICHT betrachten\"><a target = '_blank' href = path..''><button type = \"button\" class = \"btn blue btn-xs\"><i class=\"fa fa-eye\"></i></button></a></td>
OR
$vorname = get_user_vorname($user_id);
I also need to format some IDs i read from the DB with a function to a specific value.
So, how can i do this with the server side scipting?
I searched a lot, but couldn't find any solution to do this.
Does anyone know how this is possible?
Best regards, Chris
Answers
The easiest way I've found to do it is to format my response from the server side ajax page in exactly the format I want. That means my data being sent back from the ajax page is already in JSON format. In that manner, I can pass HTML (escaped) directly in the response.
This fiddle shows that you can use HTML. It's not ajax based, but for ajax based (server side page), you return json data, preformatted, and dataTables will render it. Use http://jsonlint.com/ to make sure you response is a valid json response.
https://jsfiddle.net/glenderson/yg1w6gen/1/
ok, thanks!
I will try it.
Hy,
it works well.
I only have an issue with some columns i must read for some calculating.
For example the first column, it's the id, i only need it to create some links with the id in the url.
But now the first column in the table is also shown in the Datatable. I don't want to display this column. Is there a way don't show some columns?
$columns = array(
array( 'db' => 'id', 'dt' => 0 ), #don't want to show this column
array( 'db' => 'column 1', 'dt' => 1 ),
array( 'db' => 'column 2', 'dt' => 2 ),
array( 'db' => 'column 3', 'dt' => 3 ),
.....
Chris