(02-17-2015, 04:55 PM)includebeer Wrote: It's not a broken table, it's an empty table. And the faster loading time of the page is just a side effect that I like. It's certainly not the main reason why I do it this way! The main reason is to prevent having PHP and JS code doing the same thing. Coding things in double is the best way to have nasty bugs!
If the purpose of a table is to display data, how is an empty table not broken (except in the very strict sense that the spec allows a table to contain zero or more rows)?
I understand the desire not to duplicate code between PHP and JavaScript. However, as CroNiX mentioned, you can also load the data into a partial view in PHP and send it over, leaving the script to simply insert it into the DOM. Additionally, you could load the same partial view and insert the initial data set on the server side before sending the page without duplicating any code.
The points I'm trying to make are:
- JavaScript should not be required to access your content, and
- triggering a second request on page load is not usually as efficient as it seems.
Even with something as feature-rich as DataTables, I can output an HTML table with all of the functional elements implemented without script (though requiring additional requests as the user interacts with the table), then have the script enhance the table by making all of those features work via AJAX requests or even directly on the client. Or, if you really want to go without implementing any functionality in PHP, you just output the full table and have the script implement all of the features on the client (the non-JS users don't get some of the niceties, but at least they have the data).