Jun 11, 2009

JQuery: Scrollable Table with Frozen Headers

After much difficult searching to no avail, I finally have completed a jQuery based process to create a scrollable table with fixed headers. The following code requires the header rows to be within a "thead" tag, the table body in a "tbody" tag and the entire table in a tag with the "overflow" style set to "auto" or "scroll".

This script creates a new table cloning the "thead" section and attaching it to the absolute top of the containing element so that it does not move when the containing element is scrolled.

As always I release this script under Creative Commons license, and is compatible with all browsers which are compatible with jquery except for Firefox 2.0 (a few minor alignment issues i plan to fix when i have time).

EDIT: Code Move to Snipplr

Tested and working with:

  • Internet Explorer(Win) (6.0, 7.0, 8.0)
  • Firefox(Win, Linux) (3.0)
  • Safari(Win, Mac) (3.0)
  • Chrome (Win) (2.0)
  • Opera (Win) (9.6)

Tested and having issues with:

  • Firefox (All) (1.0, 1.5, 2.0)

Edit:

It was brought to my attention that I forgot to include an example. So here's a quick and dirty one. I've tried to mark it clearly in the source so it will be easy to grab.

  1. Build and style your table inside a div that has a limited height and "overflow" style at auto
  2. Include the function above in your scripts
  3. When document is "ready" call "scrollableTable()" function with the container of the table (".scrollContainer") and, if you choose, the class name to be applied to the new header as arguments.

I will try to type up some better documentation on this and clean up the code a bit, but in the mean time please let me know of any issues you may run into so that I can fix them soon.

Column 1 Column 2 Column 3 Column 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
data 1 data 2 data 3 data 4
Update 10/27/09:
This project has fallen by the wayside due to lack of time and a redesign of the site I needed this script for anyway. I may get back to it later, but in the mean time, I've moved the code to Snipplr (link above). Feel free to further comment there. I would be happy to include any contributions/bug fixes anyone may have or link to a derivative work anyone else may be working on.

Aug 12, 2008

On Patriotism

No party holds the privilege of dictating to me how I shall vote. If loyalty to party is a form of patriotism, I am no patriot. If there is any valuable difference between a monarchist and an American, it lies in the theory that the American can decide for himself what is patriotic and what isn’t. I claim that difference. I am the only person in the sixty millions that is privileged to dictate my patriotism.
- Mark Twain

May 30, 2008

Free mp3 player for all

So I got tired of never being able to find a simple and free Flash mp3 player for my site so I just built one. I'm throwing the code into the wild under Creative Commons, so if you want it, it's yours. I'm also making the original FLA available too, so you can customize it more if you'd like. Undone MP3 Flash Player Licensed Under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported SWF - FLA(source) - Doc - ZIP (Source)

<embed type="application/x-shockwave-flash" style="" id="audio0" name="audio0" src="unMP3.swf" quality="high" wmode="transparent" flashvars="songUrl=song.mp3&autoplay=0&color1=999966&color2=002233&txtColor=778855" width="175" height="25"></embed>
FlashVars: Required-
  • SongUrl - required - URL of mp3 file to play
Optional-
  • autoplay - (default: 0) set to 1 to autoplay when movie is loaded
  • Color1 - HEX value of color for player background and progress bar
  • Color2 - HEX value of color for load progress bar and play button
  • txtColor - HEX value of color for text and border of player
Jonathan Coulton - Code Monkey

May 15, 2008

The tradition of liberty is all

"Before we know where we are, we shall have the full apparatus of totalitarianism. This young boy is a living witness to these diabolical proposals. The people - the common people - must know, must see. There are great traditions of liberty to defend. The tradition of liberty is all. The common people will let it go. Oh yes. They will sell liberty for a quieter life - that is why they must be led..."
- Mr. Alexander - Clockwork Orange

May 5, 2008

Pentagon Plans to Develop Green Zone With Condos & Malls

Forget the rocket attacks, concrete blast walls and lack of a sewer system. Now try to imagine luxury hotels, a shopping center and even condos in the heart of Baghdad. That’s all part of a 5yr. development “dream list” or what some dub an improbable fantasy to transform the U.S.-protected Green Zone from a walled fortress into a centerpiece.
Army Times - Via Digg

Really?!?!?! What the fuck??? $5 BILLION to build a mall, hotels and condos in the Green Zone!!! IN IRAQ!!!! That's 5,000,000,000 dollars. That's money well spend. This is a five year plan, put together by the Pentagon. Which means at least five more years over there, spending our money over there, as our streets fall apart, our gas and food prices go through the roof and our borders stay porous and unprotected.

Now to be fair, when we went in, I did feel we needed to go in, because many believed Iraq was a threat, many of us did believe they had the weapons, and many did believe they had something to do with 9/11. But we took out the government that would have been a threat. Though I'm not sure enough to say the weapons were never there, we did not find ANYTHING. And it has been proven they had NOTHING to do with 9/11.

Now, to stay there, we're told that we are there to promote democracy and freedom. This is not democracy or freedom. This is a nation telling another nation, which they are occupying, what their local economy and government needs to do. If this was democracy and freedom their government would have the freedom to decide what commercial centers are built and who would be building there. I'm pretty sure it wouldn't be the Marriot Hotel chain. It would be local business owners, where the money would stay in their economy. It would the local Iraqis working in and owning the shops. It would not be a bunch of Americans bringing their westernized shopping centers.

“When you have $1 billion hanging out there and 1,000 employees lying around, you kind of want to know who your neighbors are.”

Why are $1 billion just "hanging out there"??? If you have 1,000 paid employees lying around you either put them to work or send them home. Instead of building an amusement park for the people who are not Iraqis that are living there, how about we give control over to the elected officials of that government and let them decide what is best for them. If they want us out, which they have said repeatedly they do, then we should get out. If they choose to elect the leaders which do not agree with our vision, then that is too bad. If that is what they choose then allow them to have it.

"Does God want goodness or the choice of goodness? Is a man who chooses to be bad, perhaps, in some way better than a man who has the good imposed upon him?" A Clockwork Orange - Anthony Burgess

This is not, or maybe it's "should not be", what we are over there for. We are claiming to be over there helping people rebuild their lives, not to run it for them. Let them rebuild their lives and get the hell out of their way.