File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Fixed Table Header and changing classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Fixed Table Header and changing classes" Watch "Fixed Table Header and changing classes" New topic
Author

Fixed Table Header and changing classes

Joshua Ewart
Greenhorn

Joined: Jan 02, 2009
Posts: 3
Hey folks.

First time poster, be gentle with me.

I am currently having an issue with an internal webiste that has been causing me considerable grief.

I have tables with fixed header rows that are working well, with one very irritating exception.

We use an method on our text boxes to perform validation.

If the field has an error, we change the color of the text box to represent this. If the field is fine, we set it to the original color it was before we flagged it as an error. Pretty normal, right?

Well, this is when things get interesting. If the user scrolls down any amount in the table, and then clicks in and then out of the field, triggering the onblur, the fixed header jumps right out of the table. It's as if the top value is being set to where it WOULD have been in the table had the position not been set to relative. Further scrolling will not move the header from it's position on the page, until the onblur triggers again, with the header moving to a different position.

The problem is not with the onblur event or the text boxes. I have placed a button outside of the table and container div, and used it to cause the same problem by changing the class of a tr or td.

Some more background info before I post code.
  • 1 It only occurs in IE7. (The only browser I need to support.)
  • 2 I know a way to fix the problem using an expression involving scrollTop on the headerRow, but I'd like to avoid it for performance reasons.
  • 3 The table MUST be variable width.
  • 4 I absolutely need to set a class, and not set individual styles. I have 100+ pages that use the validation classes in the js validation routines.
  • 5 The outer table is only there to force the container div to be the width of the scrolling table.


  • Here's the code. Sorry for the size. Make sure to change onblurMeth to onblur before trying this sample.

    Eric Pascarello
    author
    Rancher

    Joined: Nov 08, 2001
    Posts: 15376
        
        6
    So when the browser redraws the element it forgets what it is doing.

    One thing to note is your code will not run in Firefox, look at this:

    http://www.imaputz.com/cssStuff/bigFourVersion.html

    Eric
    Joshua Ewart
    Greenhorn

    Joined: Jan 02, 2009
    Posts: 3
    Thanks for the reply, Eric.

    As I said, it appears as if IE forgets to reset the top position after the inner styles get updated.

    And it's an internal company website, so I only need to support IE7. Did you remember to change onblurMeth to onblur?

    Also, I have looked at that website multiple times. It does not appear to work in IE7.

    Again, thanks for taking the time to look at this.
    Eric Pascarello
    author
    Rancher

    Joined: Nov 08, 2001
    Posts: 15376
        
        6
    I looked at it and could not come up with anything.

    Eric
    Eric Pascarello
    author
    Rancher

    Joined: Nov 08, 2001
    Posts: 15376
        
        6

    I had an idea today, you will have to live with a flicker



    Eric
    stef li
    Greenhorn

    Joined: Jan 16, 2006
    Posts: 27
    the direct and correct method to resolve this issue is to use expression in css!
    if you use javascript to set the position of header when onscroll invoked, it would not run well as you expect.

    like


    This guy is so lazy!!!<br />There is nothing left!
    Eric Pascarello
    author
    Rancher

    Joined: Nov 08, 2001
    Posts: 15376
        
        6
    Just a warning: Expressions in CSS can have very bad performance with IE.

    Eric
    Joshua Ewart
    Greenhorn

    Joined: Jan 02, 2009
    Posts: 3
    Just a warning: Expressions in CSS can have very bad performance with IE.

    Eric


    Agreed. Which is why I'm making this change.

    Pretty nifty suggestion for that changeClassTest function, Eric.

    Unfortunately, I'm working with a VERY large dataset, and even if I cache the elements it's horrendously slow...
    Also, I'd need to modify all of my pages that are doing validation to implement it.

    Again, that's for the input. I just wish I need why changing the className was causing IE to flip the heck out...
    Eric Pascarello
    author
    Rancher

    Joined: Nov 08, 2001
    Posts: 15376
        
        6
    You might be better off breaking your table into two. One for the header and one for the body. Add a scrollable div with a set height and stick your body table in that. You will either need to hard code the width values of the columns so they line up or use a JavaScript function to figure out the widths and adjust the columns.

    Eric
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Fixed Table Header and changing classes