2011-07-06 8 views
0

テーブルのヘッダーをフリーズしようとしています。私はthis同じを達成するためにプラグインを使用しています。
このプラグインを使用したとき、私はthis.table_obj is undefinedを得ました。私は問題点を見つけようとしましたが、解決策を得ることができませんでした。 このコードを普通のhtmlファイルで試したところ、サーバー側では動作しませんでした。 あなたはエラーhereを見ることができます。
私はこのエラーが発生している理由は何ですか?jqueryでテーブルのヘッダーをフリーズ

答えて

0

を見ることができます -

ここで私が書かれているプラ​​グインです。

(function($){ 
$.fn.scrollbarTable=function(i){ 
var o={}; 
if(typeof(i)=='number')o.height=i; 
else if(typeof(i)=='object')o=i; 
else if(typeof(i)=='undefined')o={height:300} 
return this.each(function(){ 
var $t=$(this); 
var w=$t.width(); 
$t.width(w- 
function(width){ 
    var parent,child; 
    if(width===undefined){ 
     parent=$('<div style="width:50px;height:50px;overflow:auto"><div style="height:50px;"></div></div>').appendTo('body'); 
     child=parent.children(); 
     width=child.innerWidth()-child.height(99).innerWidth();parent.remove(); 
    } 
    return width; 
}()); 
var cols=[]; 
var tableCols=[]; 
$t.find('thead th,thead td').each(function(){cols.push($(this).width());}); 
$t.find('tr:eq(1) th,thead td').each(function(){tableCols.push($(this).width());}); 
var $firstRow=$t.clone(); 
$firstRow.find('tbody').remove(); 
$t.find('thead').remove(); 
$t.before($firstRow); 
$firstRow.find('thead th,thead td').each(function(i){$(this).attr('width',cols[i]);}); 
$t.find('tr:first th,tr:first td').each(function(i){$(this).attr('width',tableCols[i]);}); 
var $wrap=$('<div>'); 
$wrap.css({width:w,height:o.height,overflow:'auto'}); 
$t.wrap($wrap);})};}(jQuery)); 

使用方法:

$(document).ready(function(){ 
    $('table#tabss').scrollbarTable(); 
} 

はそれがどこかで誰かを助けることを願っています。..

任意の方法のおかげで、あなたのすべてにあなたの親切なサポートのために... :)

1

私はJavaScriptコードがテーブルIDを期待してテーブルを取得すると思います。おそらく、javascriptコードを呼び出すときや誤ったテーブルIDを指定したとき、またはテーブルマークアップにテーブルIDがないときは、テーブルIDを指定していない可能性があります。

しかし、あなたは他のいくつかのjQueryプラグインを見ていること - http://www.farinspace.com/jquery-scrollable-table-plugin/

あなたの質問には、次の質問と何らかの関係を持っています。だから、あなたはまた、私は(質問に尋ねとして)私の目標を達成するために休閑コードを書かれていること

https://stackoverflow.com/questions/983031/jquery-how-to-freeze-table-header-and-allow-scrolling-of-the-rest-of-the-rows

関連する問題