473,472 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Simulating freeze panes

I would like to freeze column and row headings on a webpage, simulating
freeze panes as in an Excel spreadsheet.

Don't seem to be able to do it with Frames. Is there a way with Javascript
and/or CSS and or Frames?

Thanks in anticipation.
May 19 '06 #1
4 13829
Roger Withnell said the following on 5/19/2006 6:54 PM:
I would like to freeze column and row headings on a webpage, simulating
freeze panes as in an Excel spreadsheet.
What is "freeze panes"?
Don't seem to be able to do it with Frames. Is there a way with Javascript
and/or CSS and or Frames?


Make each row a DIV tag, with autoscroll set to true. Then set it to
false when you want to lock it. It would be a major pain to make all the
non-locked one's scroll together though.....
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 19 '06 #2
Roger Withnell wrote:
I would like to freeze column and row headings on a webpage, simulating
freeze panes as in an Excel spreadsheet.

Don't seem to be able to do it with Frames. Is there a way with Javascript
and/or CSS and or Frames?


This is just a start, so you can develop it too, but here is an example developed with YAHOO's javascript UI toolkit: http://developer.yahoo.com/yui/

Column resizing hits limits where the browser refuses to resize any further. That needs detecting, but this is ongoing development...

Put it into the examples\animation directory:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Animation Example - Size</title>
<style type="text/css">
..Table {
border-collapse:collapse;
}

..Table tbody td {
border:1px solid black;
overflow:hidden;
}

..Table thead th {
white-space:nowrap;
background-color:buttonface;
border:1px inset;
overflow:hidden;
}
</style>
<script type="text/javascript" src="../../build/yahoo/yahoo.js"></script>
<script type="text/javascript" src="../../build/event/event.js"></script>
<script type="text/javascript" src="../../build/dom/dom.js"></script>
<script type="text/javascript"
src="../../build/animation/animation.js"></script>

<script type="text/javascript">
function Table(id, width, height)
{
this.headerTable = document.getElementById(id);
this.tbody = this.headerTable.tBodies[0];
var bodyHeight = this.tbody.offsetHeight;

this.headerContainer = document.createElement("div")
this.headerContainer.style.width = width + "px";
this.headerContainer.style.overflow = "hidden";

this.bodyContainer = document.createElement("div")
var bodyContainerWidth = width;
if (bodyHeight > height)
bodyContainerWidth += 20;
this.bodyContainer.style.width = bodyContainerWidth + "px";
this.bodyContainer.style.height = height + "px";
this.bodyContainer.style.overflow = "auto";
this.headerTable.parentNode.insertBefore(this.head erContainer, this.headerTable);
this.headerTable.parentNode.insertBefore(this.body Container, this.headerTable);

this.headerTable.style.width = this.headerTable.offsetWidth + "px";
this.headerTable.className = "Table";
this.thead = this.headerTable.getElementsByTagName("thead")[0];
this.thead.className = "TableHeader";
YAHOO.util.Dom.generateId(this.thead, "TableHeader");
this.headerRow = this.thead.rows[0];
this.headerCells = this.headerRow.cells;
this.headerColgroup = document.createElement("colgroup");
this.headerTable.insertBefore(this.headerColgroup, this.thead);
for (var i = 0; i < this.headerCells.length; i++)
{
this.headerCells[i].className = "TableHeader";
var col = document.createElement("col");
col.width = this.headerCells[i].offsetWidth;
this.headerColgroup.appendChild(col);
}
this.bodyColgroup = this.headerColgroup.cloneNode(true);
this.bodyTable = document.createElement("table");

this.bodyTable.style.width = this.headerTable.offsetWidth + "px";
this.bodyTable.appendChild(this.bodyColgroup);
this.bodyTable.className = "Table";
this.bodyTable.appendChild(this.tbody);

this.headerContainer.appendChild(this.headerTable) ;
this.bodyContainer.appendChild(this.bodyTable);

var _this = this;
setInterval(function()
{
_this.headerContainer.scrollLeft = _this.bodyContainer.scrollLeft;
}, 50);

this.resizingHeaderIndex = false;
this.headerResizing = false;
this.onHeaderBoundary = false;
this.colResizeStartX;
YAHOO.util.Event.addListener(window, "mousemove", function(e)
{
var x = YAHOO.util.Event.getPageX(e);
if (this.headerResizing)
{
var xDelta = x - this.colResizeStartX;
var colWidth = parseInt(this.headerColgroup.childNodes[this.resizingHeaderIndex].width) + xDelta;
this.headerColgroup.childNodes[this.resizingHeaderIndex].width = colWidth;
this.bodyColgroup.childNodes[this.resizingHeaderIndex].width = colWidth;

var tableWidth = parseInt(YAHOO.util.Dom.getStyle(this.bodyTable, "width")) + xDelta;
this.headerTable.style.width = tableWidth + "px";
this.bodyTable.style.width = tableWidth + "px";
this.colResizeStartX = x;
}
else
{
var t = YAHOO.util.Event.getTarget(e);
if (t.className == "TableHeader")
{
var hLeft = YAHOO.util.Dom.getX(t);
var hRight = hLeft + t.offsetWidth - 2;
if ((x >= (hRight - 1)) && (x <= (hRight + 1)))
{
this.onHeaderBoundary = true;
this.resizingHeaderIndex = t.cellIndex;
document.body.style.cursor = "col-resize";
}
else
{
this.onHeaderBoundary = false;
document.body.style.cursor = "";
}
}
else
{
this.onHeaderBoundary = false;
document.body.style.cursor = "";
}
}
}, this, true);

YAHOO.util.Event.addListener(this.thead, "mousedown", function(e)
{
var t = YAHOO.util.Event.getTarget(e);
if (this.onHeaderBoundary)
{
this.colResizeStartX = YAHOO.util.Event.getPageX(e);
this.headerResizing = true;
}
}, this, true);

YAHOO.util.Event.addListener(window, "mouseup", function(e)
{
this.headerResizing = false;
document.body.style.cursor = "";
}, this, true);

};

function onLoadWindow()
{
new Table("table", 300, 100);
}

YAHOO.util.Event.addListener(window, 'load', onLoadWindow);
</script>

<link rel="stylesheet" type="text/css" href="css/anim.css">
</head>
<body>
<div id="doc">
<h1>Table Example</h1>
<br>
<table id="table" style="overflow:hidden;border:1px solid black">
<thead>
<tr>
<th>Fooooooooooooooo</th>
<th>A very wide column header</th>
<th>Bleeeeeeeeeeeeeeeeeeeeeeeeeeeetch</th>
</tr>
</thead>
<tbody>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
<tr>
<td>Foo data</td>
<td>Wide data..........................................</td>
<td>Bletch data</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
Nige ("exgardianreader")
May 20 '06 #3

Roger Withnell wrote:
I would like to freeze column and row headings on a webpage, simulating
freeze panes as in an Excel spreadsheet.

Don't seem to be able to do it with Frames. Is there a way with Javascript
and/or CSS and or Frames?

Thanks in anticipation.


Do you wish to freeze the panes with the use of a button, or just
freeze the panes on the load?
If you wished to freeze the panes on load, a way using frames would be
just to add the 'noresize' attribute of <frame> when and if you wish to
block frame resizing, the 'scrolling' attribute (using 'scrolling=no'
for no scrolling and 'scrolling=yes' for scrolling) of <frame> for
limiting client scrolling. You could use JavaScript, using dynamic
page modification, to automatically resize or scroll any of the frames
(supposing you added the 'name' attribute to each of the frames) (also,
in order to use the JavaScript scroll method, you might have to
dynamically insert the 'scrolling=yes' attribute and maybe remove the
'scrolling=no' attribute, but I am unsure).
Trying to freeze panes using a button would either be extremely hard or
extremely simple, since you could have the button in a completely
separate frame in order to have it freeze the other frames and always
be accessible, or you could make your life a ton harder by trying to
always get back to the button, or move the button with the web page.

I hope that this helps you.

I have the honor to remain your most humble and Ob't Sv't in our war
against the King.

--
Patrick Reilly
1st Coy.
Colonel Seth Warner's Regiment

May 20 '06 #4
Roger Withnell wrote:
I would like to freeze column and row headings on a webpage,
simulating freeze panes as in an Excel spreadsheet.


The answer depends entirely on which browsers you are trying to support. If
this is for an internal webapp, or you can limit the functionality to only a
subset of browsers, then it becomes an easier task.

Below is my current IE-only CSS solution, which uses expressions. Works fine
for me with tens of columns and hundreds of rows, but you can try it in your
own page:
http://www.javascripttoolbox.com/lib/scrollingdatagrid/

A more standards-compliant approach is to make the tbody element have
overflow:auto but this doesn't work in IE. It also won't lock columns to the
left, for example.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
May 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Matt Kruse | last post by:
This is a common requirement - "freeze panes" in a table, so that some header rows and some columns on the left are frozen while the body content scrolls. This makes large tables more usable on...
1
by: Dan | last post by:
I have created an Excel worksheet using automation from a VB.NET application. The worksheet is never made visible by the VB program. It is created and filled with data from a database and then...
1
by: Tom | last post by:
Does anyone know of a way to "freeze panes" in a contnuous form? Thanks! Tom
6
by: Timo | last post by:
The IT Manager where I'm working prizes "no touch" deployment above all else. The instructions I've been given are basically this: if it's possible in ASP.NET, write it in ASP.NET; use WinForms...
0
by: Nora | last post by:
Can you do a 'freeze panes' function in the data grid in VB.Net similar to what you can do in Excel? If so, how?
7
by: srinivas | last post by:
Hi, I am a asp programmer.I am displaying the db records in the html pages in a web page.I have 500 columns and 1000 rows in that html table.Here i am planning to implement the "MS-Excel Freeze...
5
by: jasperz01 | last post by:
Hi, Is it possible using Office Automation to freeze panes in Excel from Access VBA code? I've been trying some things but can't get it right... Jasper
0
by: Luqman | last post by:
How to freeze panes in crystal reports .net with ASP.Net, using Visual Studio 2005 ? Best Regards, Luqman
6
by: dmj07 | last post by:
Hi All, Like in Excel with freeze panes, I was wondering is it possible to freeze a HTML table at the top of a page so it is visible as you scroll down the page? Example table code: <table...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.