Just throwing my two cents on performance. For small (less than 100 rows, for example) tables, using a DIV will not have a significant difference in performance.
If you want to generate very long datasets, on the other hand, you must make full use of traditional HTML tables.
Brief explanation:
All this arose from my company project, where I wrote a Javascript class for procedurally generating tables for me based on SQL data (this is a reporting type of module). Anyway, I like the DIV, so I wrote it as DIV-based, like the OP example.
After some horrific performance (especially in IE8), I decided to rewrite it using only tables, as these are pretty simple tabular data in general. The tables, for some reason, are about twice as fast on my machine in Chrome. The same is true for Safari.
However, since I can not provide my working code, I wrote a small control thing that will simply allow you to try either the methodology. You will see that they are almost identical, only one uses divs with a style to mimic the standard behavior of the table, and the other only the old school table.
The only real difference is the type of element being generated, so about the only thing I can consider during delta. I'm sure it depends on the browser, but it seems to me that the elements of the table are faster.
<script type="text/javascript"> var time_start = new Date().getTime(); var NUM_ROWS = 5000; var NUM_CELLS = 8; var OLD_STYLE = 1; // toggle 0/1, true/false if(OLD_STYLE) { var table = document.createElement('table'); document.body.appendChild(table); for(var a = 0; a < NUM_ROWS; a++) { var row = document.createElement('tr'); for(var b = 0; b < NUM_CELLS; b++) { var cell = document.createElement('td'); cell.innerHTML = 'cell'; row.appendChild(cell); } table.appendChild(row); } } else { var table = document.createElement('div'); document.body.appendChild(table); for(var a = 0; a < NUM_ROWS; a++) { var row = document.createElement('div'); row.setAttribute('style','display: table-row; padding: 2px;') for(var b = 0; b < NUM_CELLS; b++) { var cell = document.createElement('div'); cell.setAttribute('style','display: table-cell; padding: 2px'); cell.innerHTML = 'cell'; row.appendChild(cell); } table.appendChild(row); } } var dt = (new Date().getTime() - time_start)/1000; console.log( dt + ' seconds' ); </script>
Dan H Jan 16 '14 at 19:59 2014-01-16 19:59
source share