I'm using jQuery DataTable plugin, but I got a concern where the scripts loading seems to take some time, so my web page is always displaying the ordinary html table first, and after all script done, the table will then become DataTable. I don't think this kind of appearance is acceptable, so I hope can get some advices here. whether I can make the scripts faster, or don't display the plain table ahead? Btw, I am calling my script from a _Scripts partial view at my _Layout.cshtml head tag
@Html.Partial("_Scripts")
(UPDATE) I tried to hide the table, and show it after the datatable initialize, however, I get a datatable without the table header. Any idea why this is happening?
$('#stocktable').hide();
// Initialize data table
var myTable = $('#stocktable').dataTable({
// Try styling
"sScrollX": "100%",
"sScrollXInner": "100%",
"bScrollCollapse": true,
// To use themeroller theme
"bJQueryUI": true,
// To use TableTool plugin
"sDom": 'T<"clear">lfrtip',
// Allow single row to be selected
"oTableTools": {
"sRowSelect": "single"
},
"fnInitComplete": function () {
$('#stocktable').show();
}
Based on @hanzolo suggestion - here's my comment as an answer (and what my dataTable looks like):
My working solution is a "dirty" trick to hide the table without using "display:none". The ordinary "display:none" style causes initialization problem for jQuery Data Tables.
First of all, place your data table in a wrapper div:
In CSS:
This solution hides the data table without using "display:none".
After the data table initialization you have to remove class from wrapper to reveal the table:
I think you should probably just load scripts in the _Layout.cshtml, after all that's what it's for. Partial views are really meant for segments that can be re-used in other areas or at the very least, rendered HTML content.
That being said, one easy thing to do would be to either hide the table until it's done loading or even hide it and show a progress indicator.
You could do something like:
UDPATE:
If the jQuery table plugin has a "success" or "finished" callback, just hide the table on page load and show it when it's done loading.
I had the same problem. Try this:
I did a very simple solution that works fine. In the DataTable initialization I used the method show():
... and in the HTML table I put the style display:none:
Good luck!
I know it's very old question, but maybe I can help someone in future, how know ... So after many hours I find the only solution that work's for me (table it will be loaded after it is rendered complete):