JAKARTAPROJECT
JAKARTA TIPJSP TIPJSP 질문&답변DATABASE TIPJAVASCRIPT TIPWEBHACKING TIP기타 TIP
자바스크립트 팁
자바스크립트 팁
자바스크립트 및 CSS 팁 게시판입니다
Scrollable HTML table
GoodBug http://www.jakartaproject.com
이미지 슬라이더 보기

Scrollable HTML table

Overview

Scrollable HTML table JavaScript code can be used to convert tables in ordinary HTML into scrollable ones. No additional coding is necessary. All you need to do is put header rows (if you need them) in THEAD section, table body rows in TBODY section, footer rows (if you need them) in TFOOT section and give your table an ID field, include the webtoolkit.scrollabletable.js file and create ScrollableTable() object after each table.

Scrollable HTML table code tested in IE5.0+, FF1.5+.

 

Source code for index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Scrollable HTML table</title>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="webtoolkit.scrollabletable.js"></script>

    <style>
        table {
            text-align: left;
            font-size: 12px;
            font-family: verdana;
            background: #c0c0c0;
        }

        table thead {
            cursor: pointer;
        }

        table thead tr,
        table tfoot tr {
            background: #c0c0c0;
        }

        table tbody tr {
            background: #f0f0f0;
        }

        td, th {
            border: 1px solid white;
        }
    </style>
</head>

<body>

<table cellspacing="1" cellpadding="2" class="" id="myScrollTable" width="400">
    <thead>
        <tr>
            <th class="c1">Name</th>
            <th class="c2">Surename</th>
            <th class="c3">Age</th>
        </tr>
    </thead>

    <tbody>
        <tr class="r1">
            <td class="c1">John</th>
            <td class="c2">Smith</th>
            <td class="c3">30</th>
        </tr>
        <tr class="r2">
            <td class="c1">John</th>
            <td class="c2">Smith</th>
            <td class="c3">31</th>
        </tr>
        <tr class="r1">
            <td class="c1">John</th>
            <td class="c2">Smith</th>
            <td class="c3">32</th>
        </tr>
        <tr class="r2">
            <td class="c1">John</th>
            <td class="c2">Smith</th>
            <td class="c3">33</th>
        </tr>
        <tr class="r1">
            <td class="c1">John</th>
            <td class="c2">Smith</th>
            <td class="c3">34</th>
        </tr>
        <tr class="r2">
            <td class="c1">John</th>
            <td class="c2">Smith</th>
            <td class="c3">35</th>
        </tr>
        <tr class="r1">
            <td class="c1">John</th>
            <td class="c2">Smith</th>
            <td class="c3">36</th>
        </tr>
        <tr class="r2">
            <td class="c1">John</th>
            <td class="c2">Smith</th>
            <td class="c3">37</th>
        </tr>
    </tbody>

    <tfoot>
        <tr>
            <th class="c1">Name</th>
            <th class="c2">Surename</th>
            <th class="c3">Age</th>
        </tr>
    </tfoot>
</table>

<script type="text/javascript">
var t = new ScrollableTable(document.getElementById('myScrollTable'), 100);
</script>

</body>
</html>

 

Source code for webtoolkit.scrollabletable.js

/**
*
* Scrollable HTML table
* http://www.webtoolkit.info/
*
**/

function ScrollableTable (tableEl, tableHeight, tableWidth) {

    this.initIEengine = function () {

        this.containerEl.style.overflowY = 'auto';
        if (this.tableEl.parentElement.clientHeight - this.tableEl.offsetHeight < 0) {
            this.tableEl.style.width = this.newWidth - this.scrollWidth +'px';
        } else {
            this.containerEl.style.overflowY = 'hidden';
            this.tableEl.style.width = this.newWidth +'px';
        }

        if (this.thead) {
            var trs = this.thead.getElementsByTagName('tr');
            for (x=0; x<trs.length; x++) {
                trs[x].style.position ='relative';
                trs[x].style.setExpression("top", "this.parentElement.parentElement.parentElement.scrollTop + 'px'");
            }
        }

        if (this.tfoot) {
            var trs = this.tfoot.getElementsByTagName('tr');
            for (x=0; x<trs.length; x++) {
                trs[x].style.position ='relative';
                trs[x].style.setExpression("bottom", "(this.parentElement.parentElement.offsetHeight - this.parentElement.parentElement.parentElement.clientHeight - this.parentElement.parentElement.parentElement.scrollTop) + 'px'");
            }
        }

        ;


}

 

http://www.webtoolkit.info/scrollable-html-table.html

 

2008-01-16 00:26:06
220.70.88.***

 

좋은생각 ^^

첨부파일 (총 2개)
  1. index.html 2.04 KB (104 다운로드)
  2. webtoolkit_scrollabletable.js 3.31 KB (94 다운로드)
0점 (0명)
덧글 0개 | 태그 1개 | 관련글보기
태그입력
쉽표(,)구분으로 한번에 여러 태그를 입력할수 있습니다
scrollable table (1)
이름 비밀번호
자바스크립트 팁
자바스크립트 및 CSS 팁 게시판입니다
! 번호 제목 글쓴이 일자 조회
220 img 이미지 부드럽게 줄이기 1 GoodBug 2009-12-18 8,159
219 rss xml 파싱하는 모듈 입니다. 1 고고싱 2009-11-27 7,610
218 트리 입니다 . 1 고고싱 2009-11-27 5,846
217 에러처리 1 kaiser 2009-05-11 6,060
216 웹페이지 복사 방지 해지 하는 법 kaiser 2009-05-03 11,645
215 javascript 한글 짜르기 1 1 kaiser 2008-08-14 7,953
214 rolling 롤링 스크립트 1 2 GoodBug 2008-07-11 10,103
213 alert 메시지를 print 처럼 사용하기 2 고고싱 2008-06-10 8,642
212 onload onload 펑션이 정의되어 있는 상황에서 onload에 추가하기 1 GoodBug 2008-04-11 8,417
211 javascript 자바스크립트 개발가이드 4 1 kaiser 2008-04-09 8,866
210 escape HTML escpae code 1 GoodBug 2008-04-02 6,472
209 optgroup SELECT 목록 그룹별로 묶기 1 1 GoodBug 2008-03-06 8,192
208 동적 테이블 테이블에 동적 TR 삽입 및 삭제 IE, FF 공용 1 GoodBug 2008-01-18 11,717
207 drag Javascript drag and drop 1 1 GoodBug 2008-01-16 8,137
206 sort Sortable HTML table 2 GoodBug 2008-01-16 7,375
scrollable table Scrollable HTML table 1 GoodBug 2008-01-16 7,057
204 CSS CSS centered layout 1 1 GoodBug 2008-01-16 6,656
203 utf8 Javascript UTF-8 1 GoodBug 2008-01-16 7,885
202 encode Javascript url decode, encode 2 GoodBug 2008-01-16 8,100
201 암호화 Javascript MD5 2 GoodBug 2008-01-15 7,336
copyright 2005-2018 by Unicorn