How to render table before inserting it onto a page?
How to render table before inserting it onto a page?
Hi all,
Is it possible to generate a table based on HTML that is not currently present in the DOM?
Scenario (NodeJS):
- Client presses a button in the DOM
- A call is made to the server which retrieves a HTML table
- This table is appended to the DOM using JavaScript
- _$('#myTable').DataTable(......) _ is invoked, which turns the raw HTML into a nice DataTable.
However, this approach has a drawback; because the raw table is appended to the DOM before .DataTable(...) is invoked, there is a split second where the raw table HTML is visible (rather than the generated DataTable).
To prevent this, I wonder if it is possible to render the table on the HTML retrieved from the server before it is inserted into the DOM:
- Raw table HTML is retrieved from server
- .DataTable(...) is invoked on this HTML
- The HTML (which now contains the HTML as generated by .DataTables(...)) is inserted into the DOM.
Thanks for reading!
This question has an accepted answers - jump to answer
Answers
You wouldn't be able to pass the HTML to DataTables, so that's a no-goer. But there are a couple of options
ajax
,Colin
Alright. Thanks for the clarification!