My table loads twice: once full, and then with paging.
My table loads twice: once full, and then with paging.
yizhar
Posts: 9Questions: 2Answers: 0
I'm using wordpress and here is my page: http://torhazahav.org/Heathrow/
Thanks in advance.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Title of the question has been corrupted, I've meant the table is loaded once with full length and later on with paging display.
I want it to be displayed once - with paging display only.
I think it could be because you use html as the source of the datatable. It first makes the HTML table, and then applies the datatable styling/paging to it. Try making an ajax request instead and retrieve your data as a json string.
Thanks kaiaeberli, actually I thought it might be the reason and try it but couldn't make it work through Ajax.
If you could please point me to an example how to make ajax request and retrieve data as JSON with WordPress, cause the examples in the dataTables weren't clear to me (https://datatables.net/reference/option/ajax).
Thanks again!
below the code - it would require jquery to be imported
Thanks man!
Hey man, if you know a little Wordpress and can tell me where goes each code piece, that would help...
I assume some of these should go to functions.php, as an HTML header fragment, and other should go to the page body and the server...
Unfortunately I am not familiar with Wordpress. Normally you can put everything in a script tag in the html page body, and make the server return correctly formatted json upon request.
Thanks again!
I've tried you code my friend, got lost a little (learned Ajax thanks to you now.. :) ), and then I went back to dataTables Ajax example - surprisingly everything works now, I've probably made a stupid mistake before.
Now I've wonder - if their example includes 4 lines of code, why do I need all your code? It gives you better resolution/control for working with the data?
Here is the dataTables example which works for me as is:
$(document).ready(function() {
$('#example').dataTable( {
"ajax": "data/arrays.txt"
} );
} );
Yes exactly: it gives you more granular control over the result, as well as making table creation more generic.
For example, imagine you have a SQL query where you define column names. My code would pickup those names from the json response to build the table, whereas in the ajax example from datatables they are defined in the html or table definition (so instead of one place i'd have to define columns in two places, and keep those in sync).
Second, my code allows you to format data for display (for example in lower precision), while at the same time keeping the original data intact to use for something else (export to excel for example, or sorting).
However, I agree that for the POST and GET requests, you could use the ajax option directly (in fact it seems to take exactly the same parameters as the jquery version), if you are happy to specify your column names manually in the table definition.
Thanks, clear now.