简体   繁体   English

具有顶行和左列冻结的可滚动HTML表

[英]Scrollable HTML table with top row and left column frozen

Has anyone been able to implement a scrollable table in HTML where the TOP row and LEFT columns are frozen, but the rest of the table is scrollable? 有没有人能够在HTML中实现一个可滚动的表,其中TOP行和LEFT列被冻结,但表的其余部分是否可滚动? A perfect example of this is: Google Squared 一个很好的例子是: Google Squared

I tried to reverse engineer the code for the google squared table, but I have been unsuccessful so far. 我试图对谷歌平方表的代码进行逆向工程,但到目前为止我还没有成功。

Note: I need the ability to FREEZE the TOP ROW and the LEFT COLUMN at the same time. 注意:我需要能够同时冻结TOP ROW和LEFT COLUMN。

There's a working example at http://ajaxian.com/archives/freeze-pane-functionality that should be easy to duplicate. http://ajaxian.com/archives/freeze-pane-functionality上有一个易于复制的工作示例。 Be sure to note the comments -- many of the users have made helpful suggestions for improving the script. 请务必记下评论 - 许多用户已经为改进脚本提出了有用的建议。

Per @Nirk's request, a direct link to the active demo is at http://www.disconova.com/open_source/files/freezepanes.htm . 根据@Nirk的要求,有关活动演示的直接链接位于http://www.disconova.com/open_source/files/freezepanes.htm

Go with a basic structure like this- 使用像这样的基本结构 -

table
  row
    column (blank)
    column
      table (1 row high, column headers)
  row
    column 
      table (1 column wide, row headers)
    column
      div (fixed height & width, overflow auto)
        table (actual data)

Set a fixed table-layout and specify column widths in pixels explicitly. 设置固定的表格布局并明确指定列宽(以像素为单位)。 You should be able to achieve the same effect. 你应该能够达到同样的效果。

i have a version of this in use (for a Gantt-chart style display). 我有一个正在使用的版本(用于甘特图样式显示)。

it uses 3 tables: 1 for left column (the rows), 1 for top (columns), and then the data. 它使用3个表:1表示左列(行),1表示顶部(列),然后是数据。

you need to work hard to get the cells to match sizes with the ones they match up to ( table layout-fixed can help achieve this). 你需要努力让单元格与它们匹配的单元格匹配( table layout-fixed可以帮助实现这一点)。

The tables then are placed in some divs; 然后把表放在一些div中; the left and top divs have (as suggested above) height & width and overflow-auto in their css. 左侧和顶部div具有(如上所述)高度和宽度以及它们的css中的overflow-auto

You then hook up some javascript to sync the scrolling of the left / top divs with the inner one... 然后你连接一些javascript来同步左/顶部div与内部的滚动...

As I recall there was a fair bit of 'curse-and-try-again', but it can be done with minimal js. 我记得有一点'诅咒 - 再试一次',但它可以用最小的js来完成。

hth 心连心

如果你使用jQuery,那么有很多用于固定头的表的插件。

You need Scrollable (jQuery plugin) 你需要Scrollable (jQuery插件)

Demo is here 演示就在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM