Solved

Scrollable Table in HTML

Posted on 2015-02-18
6
69 Views
Last Modified: 2015-02-19
HI Experts,

Does anyone have a good and easy example of a HTML table where I can lock the thead and first column of each row, then I can easily specify the height and width of the table that I want and it will lock what it needs. Where, if needed, the rest of the data will scroll vertically or horizontally.

Thank you
0
Comment
Question by:APD_Toronto
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
have you checked out datatables?

http://www.datatables.net/
0
 

Author Comment

by:APD_Toronto
Comment Utility
I just want it to add a scroll.

This used to work a couple of years ago, but I cannot remember how to make the headings "stick"

HTML:
<a href="index.php?action=logout"> <input type="button" value="Logout" id="button"> </a>
        <br>
        
        <div id="tbl-container">
            <table>
		
                <thead>
                    <th class="locked">User</th>
                </thead>
                
                <tr>
                    <td class="alt1">Reservations</td>
                </tr>
                <tr>
                    <td class="alt-1">User 2</td>
                </tr>
                <tr>
                    <td class="alt1">User 3</td>
                </tr>
                <tr>
                    <td class="alt-1">User 4</td>
                </tr>
                <tr>
                    <td class="alt1">User 5</td>
                </tr>
                <tr>
                    <td class="alt-1">User 6</td>
                </tr>
                <tr>
                    <td class="alt1">User 7</td>
                </tr>
                <tr>
                    <td class="alt-1">User 8</td>
                </tr>
                <tr>
                    <td class="alt1">User 9</td>
                </tr>
                <tr>
                    <td class="alt-1">User 10</td>
                </tr>
            </table>
        </div>

Open in new window


CSS:
input, select{
    font-size: 8pt;
}

div#tbl-container {
    width: 200px;
    height: 150px;
    overflow: auto;
    scrollbar-base-color:#ffeaff;
    margin: 10px auto;
}


thead th, thead th.locked	{
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    background-color: #FFFF66;
    border-right: 1px solid silver;
    position:relative;
    cursor: default; 
}
	
thead th {
    top: expression(document.getElementById("tbl-container").scrollTop-2); /* IE5+ only */
    z-index: 20;
}

thead th.locked {z-index: 30;}

td.locked,  th.locked {
    font-size: 12px;
    font-weight: bold;
    border-right: 1px solid silver;
    left: expression(parentNode.parentNode.parentNode.parentNode.scrollLeft); /* IE5+ only */
    position: relative;
    z-index: 10;
}

.alt1 {
    background-color: white;
}
.alt-1 {
    background-color: #ccffff;
}

Open in new window

0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
According to this article https://msdn.microsoft.com/en-us/library/ms537634%28v=vs.85%29.aspx , that method using 'expression' was obsoleted in IE8 and was only supported by Microsoft Jscript.  That means it didn't work in the other browsers.  I have some code from a question a couple of years ago, I'll see if I can find it.  It was a pain to make work.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Here http://www.imaputz.com/cssStuff/bigFourVersion.html is one that works in Firefox, Chrome, Safari, and Opera.  It doesn't work in IE8 on this machine.  It lists a bunch of old browsers that don't support it.
0
 

Author Comment

by:APD_Toronto
Comment Utility
That example actually serves my purpose.

Can you show me how to implement?

Thank you
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
You need to save a copy of the source code for that page and strip out all the parts that you don't need.  I don't see any other way to do it.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now