Home
datagrid :: CSS/HTML Implementation
Abstract

This document is inted to provide a detailed review of the Document Object Model and Cascading Style Sheet implementation used to create the Datagrid contro. The information provided here is not Javeline specific

Before I foreget, truly sorry about the example colors used here. I realize they are disgustingly ugly but they are just for demonstration purposes.

Step 1: Set up the Primary Grid Areas
header container div [z-index: 5]
content container [z-index:1]

We have set up 5 primary grid areas. These are from a css standpoint:

Notice that not only does the css have width's of 100% but also uses right:0 to define the right side of the object. The usage of width is only ncessary for IE6, IE7 understands left and right in combinations as well as top and bottom in combination. The feedback element appears when there is information to provide back to the user such as number of records in search etc. When it appears the header and content areas automatically move down. The footer element could be an optional element that caller can decide to display.

Step 2: Set up the Content Columns

One the big mistakes developers make in creating a grid interface is thinking along the lines of a HTML table object. You have to realize that the selection of a row of data is merely a function of the interface and that selecting it simply does not mean you are putting borders and or background on a element that represents the row. The only think you need to know about row selection is the vertical position of the row.

There is more functional requirements within a column that within a row. Such as resizing, sliding left or right or hiding and of course slicing text that overflows the column. In order to facilitate speed you want to be able to simply resize a master column div for each column and let the browser do the rest for you. If you doing dom iteration on row cells or modifying css your asking the browser to do a lot more than it really needs to.

For arguments sake lets assume we have 4 columns each 25% of width:

header container div [z-index: 5]
this is some really long data that I am checking for truncation
Column B
Column C
Column D

Notice and this is important, that there are no borders on the column divs. Borders, padding and margin makes your life a real nightmare because they impact on the width of a column and that is exactly what you do not want. You want to keep things as simply as possible. The CSS for the columns is as follows:

The inline style for each column div has just the width and left properties set. Color properties are there for display purposes only. In the above example the column widths are being set to 25% rather that by pixel. We will change that further on but have the same result.

I will talk about the implementing the headers a little later on as this has several layers for effect and positioning.

Step 3: Setting up the Rows

Rows are real simple and again they are fixed position. Each cell exists within its column and has a set height, top, left and width. The CSS handles the positioning all we have to do inline is set the top in pixels.

header container div [z-index: 5]
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped

Depending on the browser you are running you will see some slight differences. In all supported browsers you will see the long text truncated. In IE7 and Safari you will see ellipsis following the truncated text but not in Firefox as it does not support the text-overflow:ellipsis setting. In IE6 the text is truncated but runs right up the edge of the column which is, in my opinion, pretty ugly. We will deal with this situation in Dealing with Column Percentage and Sizing document. The CSS for the cell is as follows:

Step 4: Setting up the Header Columns

Like the Content Columns the header DIV contains column divs with the same sizing as the content columns but there is some layering in effect on the headings in order to provide visual feedback on mouse actions. The layer order is as follows:

some data
some data
some data
some data
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped

The actual css styles are as follows:

For the purposes of the above example the effect layer has a 2px border red border in order to show where it sits. This results in some overlap which would normally not be there.

Step 5: Setting up the Vertical Resizer Bars

The vertical sizer bars sit at the root of the datagrid object and are simply a fixed position DIV object the entire height of the grid but sit behind the feedback and headings dom objects via the z-index. The css is as follows:

some data
some data
some data
some data
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped
Step 6: Lets drop the Ugly Colors as I have a Migrain Comming on...

Thats all of the basic structure of the datagrid DOM. I will now display it without all the ugly colors:

Column 1
Column 2
Column 3
Column 4
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped
some data
some much long data demoinstrating that the overflow is being cliped

I did not mention above as it seemed rather redundant at the time. In order to provide for multi select the content columns are wrapped in a DIV with a class of rows. There is a second DIV under content with a class of selectors. These two divs are there to help in improve in performace with regards to DOM walking.

Below is the resulting HTML

<div class="datagrid" style="">
<div class="resizer" style="left:25%"></div>
<div class="resizer" style="left:50%"></div>
<div class="resizer" style="left:75%"></div>
<div class="resizer" style="left:99.8%"></div>
<div class="feedback" style="display:block">feedback area</div>
<div class="headings" >
<div class="effect" style="width:25%; left:0%"></div>
<div class="label" style="padding-left:5px; width:25%; left:0%;">Column 1</div>

<div class="effect" style="width:25%; left:25%"></div>
<div class="label" style="padding-left:5px; width:25%; left:25%;">Column 2</div>

<div class="effect" style="width:25%; left:50%"></div>
<div class="label" style="padding-left:5px; width:25%; left:50%;">Column 3</div>

<div class="effect" style="width:25%; left:75%"></div>
<div class="label" style="padding-left:5px; width:25%; left:75%;">Column 4</div>
</div>

<div class="content" >
<div class="rows">
<div class="column" style="width:25%; left:0%">
<div class="cell" style="top:5px">some data</div>
<div class="cell" style="top:25px;">some much long data demoinstrating that the overflow is being cliped</div>
</div>
<div class="column" style="width:25%; left:25%">
<div class="cell" style="top:5px;">some data</div>
<div class="cell" style="top:25px;">some much long data demoinstrating that the overflow is being cliped</div>
</div>
<div class="column" style="width:25%; left:50%">
<div class="cell" style="top:5px;">some data</div>
<div class="cell" style="top:25px;">some much long data demoinstrating that the overflow is being cliped</div>
</div>
<div class="column" style="width:25%; left:75%">
<div class="cell" style="top:5px;">some data</div>
<div class="cell" style="top:25px;">some much long data demoinstrating that the overflow is being cliped</div>
</div>
</div>
<div class="selectors"></div>
</div>
<div class="footer" style="">Footer</div>
</div>


Conclusion

The above DOM and CSS is of course not exactly how it is. There are a couple more items that are added such as the highlighter div and the selector divs plus the header background effects but programatically the above is what is important. Now its time to move onto Step 2 - Dealing with Column Percentage and Sizing