www.fgks.org   »   [go: up one dir, main page]

Skip Navigation Links
  

Internet Explorer Developer Center

Click to Rate and Give Feedback
HTML and DHTML Overviews and Tutori...
 Enhancing Table Presentation
Enhancing Table Presentation

Microsoft Internet Explorer 5 gives the author more control over table presentation. Significantly faster rendering is now possible. Using this layout, authors can increase table rendering speeds by several orders of magnitude, particularly for longer, more complex tables.

Authors can also manipulate what table information reaches users, as well as when and how it is displayed. To this end, the author can now collapse rows and cells, render table content invisible, and join shared borders. These key features accord with the Cascading Style Sheets, Level 2 (CSS2) World Wide Web link specification, keeping Internet Explorer the leader in standards support.

This overview examines all of these new features and suggests how they may be combined with other techniques available for enhancing table presentation.

Benefits

Tables provide structured information to end users. Often, however, the amount of data overwhelms the user, or the type of information is simply not relevant. Internet Explorer solves these problems by enabling the author to show and hide information based on user actions or information gathered about the user's system.

Presentation is further improved by taking advantage of the new borderCollapse and tableLayout properties. Each of these properties adds performance gains to table rendering. With user patience usually measured in seconds, this speed is vital for delivering information to users before they move on to another page. Using the tableLayout property can easily halve the time for rendering of large tables. Faster rendering is possible with even larger tables.

Table Layout

Table rendering performance can be increased by specifying the tableLayout property. This property causes Internet Explorer to incrementally render the table, providing users with information at a faster pace. Using the tableLayout property, the layout of a table is determined in the following order:

  1. From information in the width property for the col or colGroup objects.
  2. By analyzing the formatting of the first table row.
  3. By an equal division of the columns.

First, information from the width property of the COL or COLGROUP object is used if it is available. If it is unavailable, then formatting for the first table row is taken into account. Lastly, if formatting is not available for the COL or COLGROUP objects, or the first table row, table layout is determined by an equal division of the columns.

Sample

The following example shows the use of the Cascading Style Sheets (CSS) attribute, table-layout, to fix the table layout, resulting in faster rendering of the table. Note that the widths need not be set on the TABLE and COL objects. When the width is not specified, the browser looks to the contents of the first row's cells to fix the column widths and, consequently, the table width.

<table style="table-layout: fixed" width="600">
    <colgroup>
        <col width="100"><col width="300"><col width="200">
    </colgroup>
    <tr height="20">
        <td>...</td>
        <td>...</td>
        <td>...</td>
    </tr>
    ...
</table>

The performance gains are significant, especially for large tables. Because the browser does not need to parse through the table once simply to lay it out, the table rows can start to render immediately. Click the button to view a demonstration of this rendering gain.

This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Take care in choosing the column width. Cell content that exceeds the width of the column is wrapped, if possible, or clipped if the content cannot be wrapped. If row height has been set, the wrapped text will be clipped where it exceeds the height restriction. If data sources are dynamically bound to the table through data binding, consideration of all the content that may appear is especially important.

Collapsing or Hiding Rows and Cells

Too much information can confuse or distract your readers. To aid your readers and improve their comprehension of important data, you can selectively show information or you can enable the user to selectively view information. A number of techniques are available to achieve this end.

Hiding the full table itself is the most basic means of hiding data. This full table hiding has been available to authors since Internet Explorer 4.0. Using the display property, the entire table may be hidden and its physical space eliminated in the layout. Choosing the visibility property, on the other hand, hides the table but preserves its space in the layout.

The display and visibility properties can be limited to rows and cells. Using the display property, rows can be collapsed out of view. If, instead, you desire the space occupied by the row or cell to show, but not the information, apply the visibility property. Changing the visibility through scripting is useful for showing and hiding overlapping content based on user interaction. Note that for a child element to be visible, the parent element must also be visible. For style scripting information, see Introduction to Dynamic Styles.

Note that similar functionality is available through the data-binding filtering mechanism. Data binding may be a more appropriate choice where scalability is important. For more information, see Introduction to Data Binding.

Collapsing Rows

Collapsing rows easily hides unimportant or irrelevant information from users.

Sample

The following sample uses function calls to hide and show table rows and cells. If the user is interested only in household pets, the display property on the rows that do not have household pets is set to "none" on the onclick event.

<script type="text/javascript">
function getPets() {
    tblChoice1.style.display="none";
    tblChoice2.style.display="";
    tblChoice3.style.display="none";
}
</script>
...
<table>
    <tr id="tblChoice1">
        <td>Horses</td>
        <td id="tblChoice1_1">Thoroughbreds</td>
        <td>Fast</td>
    </tr>
    <tr id="tblChoice2">
        <td>Dogs</td>
        <td id="tblChoice2_1">Greyhounds</td>
        <td>Fast</td>
    </tr>
    <tr id="tblChoice3">
        <td>Marsupials</td>
        <td id="tblChoice3_1">Opossums</td>
        <td>Slow</td>
    </tr>
</table>
...
<input type="button"  value="Show household pets">
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Note that the author may use inline scripting to achieve the same result by replacing the onclick call in the last line above with:

Hiding Information in Rows and Cells

Visibility can be set on individual cells, groups of cells, rows, or tables to hide information while maintaining the physical space occupied by the data. The following sample uses function calls to hide and show table cells. For example, if the user is interested only in fast pets, the visibility property on the rows that do not have fast pets is set to "hidden" on the onclick event.

Sample

<script type="text/javascript">
function getFast() {
    tblChoice1_1.style.visibility="visible";
    tblChoice2_1.style.visibility="visible";
    tblChoice3_1.style.visibility="hidden";
}
</script>
...
<table>
    <tr>
        <td>Horses</td>
        <td id="tblChoice1_1">Thoroughbreds</td>
        <td>Fast</td>
    </tr>
    <tr>
        <td>Dogs</td>
        <td id="tblChoice2_1">Greyhounds</td>
        <td>Fast</td>
    </tr>
    <tr>
        <td>Marsupials</td>
        <td id="tblChoice3_1">Opossums</td>
        <td>Slow</td>
    </tr>
</table>
... 
<input type="button"  value="Show fast pets"> 
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Hiding Information in Multiple Rows

The display property can be set on groups of rows to hide information while maintaining the physical space occupied by the row. Using the TBODY object within the TABLE object, the author can specify the rows to which the display property is applied.

Sample

In the following example, the information contained between the TBODY objects is toggled depending on the user's choice.

<table style="table-layout: fixed">
    <colgroup>
        <col width="100"><col width="150"><col width="150">
    </colgroup>
    <tr>
        <td>EST</td>
        <td>9:00 A.M.</td>
        <td>5:00 P.M.</td>
    </tr>
    <tbody id="tbltb_1">
        <tr>
            <td>CST</td>
            <td>8:00 A.M.</td>
            <td>4:00 P.M.</td>
        </tr>
    </tbody>
    <tbody id="tbltb_2">
        <tr>
            <td>MST</td>
            <td>7:00 A.M.</td>
            <td>3:00 P.M.</td>
        </tr>
    </tbody>
    <tr>
        <td>PST</td>
        <td>6:00 A.M.</td>
        <td>2:00 P.M.</td>
    </tr>
</table>
<p><button >Hide 
CST</button>
<button >Hide MST
</button></p>
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

The advantage here is in the coding: setting the visibility property on each row in a large table is cumbersome. Leveraging the tBody object accomplishes this goal with less script.

Joining Borders

Authors can also collapse interior borders to keep a consistent width on all the borders in the table. Although borders should not overwhelm the data itself, traditional table rendering results in double-width borders between cells. Internet Explorer 5 allows you to maintain a consistent border width throughout the table.

Sample

The following example uses the border-collapse CSS attribute on the TABLE object, as shown in the following code. Alternately, the borderCollapse property could be used to script the same functionality.

<table id="id1" style="border-collapse: collapse">
    <tr>
        <td>EST</td>
        <td>9:00 a.m.</td>
    </tr>
    <tr>
        <td>CST</td>
        <td>8:00 a.m.</td>
    </tr>
    <tr>
        <td>PST</td>
        <td>6:00 a.m.</td>
    </tr>
</table>
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Authors now can show tables emulating the thin border lines used in Microsoft Excel, as shown in the following table (the collapsed borders will only be evident if you are using Internet Explorer 5).

EST 9:00 a.m. 5:00 p.m.
CST 8:00 a.m. 4:00 p.m.
PST 7:00 a.m. 2:00 p.m.

The look of the preceding table is achieved using the following embedded style sheet:

<style type="text/css">
td {
    border: 'thin black solid';
}
</style>

The same table without collapsed borders (that is, in standard HTML) uses more space between the cells in order to render the detached borders.

EST 9:00 a.m. 5:00 p.m.
CST 8:00 a.m. 4:00 p.m.
PST 6:00 a.m. 2:00 p.m.

Not only do authors have a new choice between these two styles of borders, additional styles can be attached to either using the CSS border properties.

Printing Tables on Multiple Pages

When a page containing a table is printed, the CSS attributes page-break-before and page-break-after can be used to specify where in a table the break should occur. This is helpful for Web sites that implement large tables to organize pages. In addition, the display property exposes the table-header-group and table-footer-group possible values, which specify that the tHead or tFoot objects are always before or after any table rows. Using these possible values for the tHead and tFoot objects specifies that the header and footer will print on every page that a particular table spans.

Conclusion

With the Internet evolving into a repository of structured information, presenting data to users requires careful planning by page authors. Internet Explorer 5 gives you, the author, important new presentation tools to assist in this task.

Related Topics

Tags What's this?: Add a tag
Community Content
 
Add Community Content
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker
DCSIMG