冻结jquery中的表头 [英] Freeze table header in jquery
问题描述
我试图冻结表头。我使用 此 插件实现相同。
当我使用这个插件,我得到 this.table_obj is undefined
。我试图找出什么是问题,但不能得到的解决方案。
当我试图在纯html文件中的代码工作,但不是在服务器端。
,您可以看到 此处 错误。
任何建议为什么我得到这个错误?
I am trying to freeze table header. I am using this plugin to achieve the same.
When I used this plugin I got this.table_obj is undefined
. I tried to find out what's the problem but couldn't get the solution.
When I tried this code in plain html file it works, but not on server side.
you can see the error here..
Any suggestion why I am getting this error?
推荐答案
我写了fallowing代码为了实现我的目标问题) -
i have written fallowing code in order to achieve my goal(as asked in question)-
这里是我写的插件。
(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();
}
希望它能帮助某人。
方式感谢所有的人你的支持...:)
Any way thanks to all of you for your kind support... :)
这篇关于冻结jquery中的表头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!