Skip to content Skip to sidebar Skip to footer

Efficiently Representing A Large Grid In A Browser

I need to display and manipulate, in a browser, a grid of up to 10,000 simple cells (say, 100 by 100). These cells are basically just a colored-in rectangle. Manipulations include

Solution 1:


Solution 2:

For what it's worth, there's the possibility that you could use borders to have one <div> represent three, or more, areas. Though it would be awkward to ensure cross-browser compatibility (given the differences between Trident, Gecko, Webkit and Presto).

If there's a reason that the cells are, basically, tabular in their presentation you could use a table. Which would simplify things a little, though might be non-semantic depending on your use-case.

Also, personally I'd test creating this, with the options you've got available, for tables, divs, lists (probably ul, but it depends on your use-case of course)...and then just go with what you find is the fastest.

I'd recommend using CSS-sprites for the background/colouring of each cell if they're going to be a predictable height width, just to conserve some bandwidth.


In response to the question in comments:

To have one div generate the colour for three areas, assuming a fixed height/width of each div of 100px.

div#3areas
{width: 100px;
height: 100px;
background-color: #f00; /* for the vertically-centred area */
border-top: 100px solid #00f;
border-bottom: 100px solid #0f0;
}

Should generate something like:

+------------------------+
|                        |
|      border-top        |
|        (#00f           |
+------------------------+
|                        |
|      central content   |
|       area (#f00)      |
+------------------------+
|                        |
|      border-bottom     |
|         (#0f0)         |
+------------------------+

But it probably won't, due to the different ways in which browsers handle borders, see: http://www.cssplay.co.uk/boxes/borders.html (albeit this is rather out-of-date, being written when IE6, Mozilla 1.5 and Netscape 7 were deemed worthy of comment).


Solution 3:

jsgraphics demonstrates use of divs for 2d drawing. In the worst case each div is a pixel and it could manage thousands of them on a canvas.

Another alternative is to only display what the user can see at the time. something like virtual scrolling area library might be useful. The idea is to only render (create the divs) for the area the user can see. google


Post a Comment for "Efficiently Representing A Large Grid In A Browser"