js固定表头或者表列(2) jquery.superTable.js

2023-10-23 08:40

本文主要是介绍js固定表头或者表列(2) jquery.superTable.js,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

效果:

代码例子:

代码

1.superTables.css:

/*
/ 
// Super Tables v0.30 - MIT Style License
// Copyright (c) 2008 Matt Murphy --- www.matts411.com
//
// Contributors:
// Joe Gallo
/ 
*/
.sBase {position: relative;width: 100%;height: 100%;overflow: hidden;
}/* HEADERS */
.sHeader {position: absolute;z-index: 3;background-color: #ffffff;
}
.sHeaderInner {position: relative;
}
.sHeaderInner table {border-spacing: 0px 0px !important;border-collapse: collapse !important;width: 1px !important;table-layout: fixed !important;background-color: #ffffff; /* Here b/c of Opera 9.25 :( */
}/* HEADERS - FIXED */
.sFHeader {position: absolute;z-index: 4;overflow: hidden;
}
.sFHeader table {border-spacing: 0px 0px !important;border-collapse: collapse !important;width: 1px !important;table-layout: fixed !important;background-color: #ffffff; /* Here b/c of Opera 9.25 :( */
}/* BODY */
.sData {position: absolute;z-index: 2;overflow: auto;background-color: #ffffff;
}
.sData table {border-spacing: 0px 0px !important;border-collapse: collapse !important;width: 1px !important;table-layout: fixed !important;
}/* BODY - FIXED */
.sFData {position: absolute;z-index: 1;background-color: #ffffff;
}
.sFDataInner {position: relative;
}
.sFData table {border-spacing: 0px 0px !important;border-collapse: collapse !important;width: 1px !important;	table-layout: fixed !important;
}/*
/ 
// Super Tables - Skin Classes
// Remove if not needed
/ 
*//* sDefault */
.sDefault {margin: 0px;padding: 0px;border: none;font-family: Verdana, Arial, sans serif;font-size: 0.8em;
}
.sDefault th, .sDefault td {border: 1px solid #cccccc;padding: 3px 6px 3px 4px;white-space: nowrap;
}
.sDefault th {background-color: #e5e5e5;border-color: #c5c5c5;
}
.sDefault-Fixed {background-color: #eeeeee;border-color: #c5c5c5;
}/* sSky */
.sSky {margin: 0px;padding: 0px;border: none;font-family: Verdana, Arial, sans serif;font-size: 0.8em;
}
.sSky th, .sSky td {border: 1px solid #9eb6ce;padding: 3px 6px 3px 4px;white-space: nowrap;
}
.sSky th {background-color: #CFDCEE;
}
.sSky-Fixed {background-color: #e4ecf7;
}/* sOrange */
.sOrange {margin: 0px;padding: 0px;border: none;font-family: Verdana, Arial, sans serif;font-size: 0.8em;
}
.sOrange th, .sOrange td {border: 1px solid #cebb9e;padding: 3px 6px 3px 4px;white-space: nowrap;
}
.sOrange th {background-color: #ECD8C7;
}
.sOrange-Fixed {background-color: #f7ede4;
}/* sDark */
.sDark {margin: 0px;padding: 0px;border: none;font-family: Verdana, Arial, sans serif;font-size: 0.8em;color: #ffffff;
}
.sDark th, .sDark td {border: 1px solid #555555;padding: 3px 6px 3px 4px;white-space: nowrap;
}
.sDark th {background-color: #000000;
}
.sDark-Fixed {background-color: #222222;
}
.sDark-Main {background-color: #333333;
}

2.superTables.js

/
// Super Tables v0.30 - MIT Style License
// Copyright (c) 2008 Matt Murphy --- www.matts411.com
//
// Contributors:
// Joe Gallo
/
// TO CALL: 
// new superTable([string] tableId, [object] options);
//
// OPTIONS: (order does not matter )
// cssSkin : string ( eg. "sDefault", "sSky", "sOrange", "sDark" )
// headerRows : integer ( default is 1 )
// fixedCols : integer ( default is 0 )
// colWidths : integer array ( use -1 for auto sizing )
// onStart : function ( any this.variableNameHere variables you create here can be used later ( eg. onFinish function ) )
// onFinish : function ( all this.variableNameHere variables created in this script can be used in this function )
//
// EXAMPLES:
// var myST = new superTable("myTableId");
//
// var myST = new superTable("myTableId", {
//		cssSkin : "sDefault",
//		headerRows : 1,
//		fixedCols : 2,
//		colWidths : [100, 230, 220, -1, 120, -1, -1, 120],
//		onStart : function () {
//			this.start = new Date();
//		},
//		onFinish : function () {
//			alert("Finished... " + ((new Date()) - this.start) + "ms.");
//		}
// });
//
// ISSUES / NOTES:
// 1. No quirksmode support (officially, but still should work)
// 2. Element id's may be duplicated when fixedCols > 0, causing getElementById() issues
// 3. Safari will render the header row incorrectly if the fixed header row count is 1 and there is a colspan > 1 in one 
//		or more of the cells (fix available)
/var superTable = function (tableId, options) {
/* Initialize */options = options || {};this.cssSkin = options.cssSkin || "";this.headerRows = parseInt(options.headerRows || "1");this.fixedCols = parseInt(options.fixedCols || "0");this.colWidths = options.colWidths || [];this.initFunc = options.onStart || null;this.callbackFunc = options.onFinish || null;this.initFunc && this.initFunc();/* Create the framework dom */this.sBase = document.createElement("DIV");this.sFHeader = this.sBase.cloneNode(false);this.sHeader = this.sBase.cloneNode(false);this.sHeaderInner = this.sBase.cloneNode(false);this.sFData = this.sBase.cloneNode(false);this.sFDataInner = this.sBase.cloneNode(false);this.sData = this.sBase.cloneNode(false);this.sColGroup = document.createElement("COLGROUP");this.sDataTable = document.getElementById(tableId);this.sDataTable.style.margin = "0px"; /* Otherwise looks bad */if (this.cssSkin !== "") {this.sDataTable.className += " " + this.cssSkin;}if (this.sDataTable.getElementsByTagName("COLGROUP").length > 0) {this.sDataTable.removeChild(this.sDataTable.getElementsByTagName("COLGROUP")[0]); /* Making our own */}this.sParent = this.sDataTable.parentNode;this.sParentHeight = this.sParent.offsetHeight;this.sParentWidth = this.sParent.offsetWidth;/* Attach the required classNames */this.sBase.className = "sBase";this.sFHeader.className = "sFHeader";this.sHeader.className = "sHeader";this.sHeaderInner.className = "sHeaderInner";this.sFData.className = "sFData";this.sFDataInner.className = "sFDataInner";this.sData.className = "sData";/* Clone parts of the data table for the new header table */var alpha, beta, touched, clean, cleanRow, i, j, k, m, n, p;this.sHeaderTable = this.sDataTable.cloneNode(false);if (this.sDataTable.tHead) {alpha = this.sDataTable.tHead;this.sHeaderTable.appendChild(alpha.cloneNode(false));beta = this.sHeaderTable.tHead;} else {alpha = this.sDataTable.tBodies[0];this.sHeaderTable.appendChild(alpha.cloneNode(false));beta = this.sHeaderTable.tBodies[0];}alpha = alpha.rows;for (i=0; i<this.headerRows; i++) {beta.appendChild(alpha[i].cloneNode(true));}this.sHeaderInner.appendChild(this.sHeaderTable);if (this.fixedCols > 0) {this.sFHeaderTable = this.sHeaderTable.cloneNode(true);this.sFHeader.appendChild(this.sFHeaderTable);this.sFDataTable = this.sDataTable.cloneNode(true);this.sFDataInner.appendChild(this.sFDataTable);}/* Set up the colGroup */alpha = this.sDataTable.tBodies[0].rows;for (i=0, j=alpha.length; i<j; i++) {clean = true;for (k=0, m=alpha[i].cells.length; k<m; k++) {if (alpha[i].cells[k].colSpan !== 1 || alpha[i].cells[k].rowSpan !== 1) {i += alpha[i].cells[k].rowSpan - 1;clean = false;break;}}if (clean === true) break; /* A row with no cells of colSpan > 1 || rowSpan > 1 has been found */}cleanRow = (clean === true) ? i : 0; /* Use this row index to calculate the column widths */for (i=0, j=alpha[cleanRow].cells.length; i<j; i++) {if (i === this.colWidths.length || this.colWidths[i] === -1) {this.colWidths[i] = alpha[cleanRow].cells[i].offsetWidth;}}for (i=0, j=this.colWidths.length; i<j; i++) {this.sColGroup.appendChild(document.createElement("COL"));this.sColGroup.lastChild.setAttribute("width", this.colWidths[i]);}this.sDataTable.insertBefore(this.sColGroup.cloneNode(true), this.sDataTable.firstChild);this.sHeaderTable.insertBefore(this.sColGroup.cloneNode(true), this.sHeaderTable.firstChild);if (this.fixedCols > 0) {this.sFDataTable.insertBefore(this.sColGroup.cloneNode(true), this.sFDataTable.firstChild);this.sFHeaderTable.insertBefore(this.sColGroup.cloneNode(true), this.sFHeaderTable.firstChild);}/* Style the tables individually if applicable */if (this.cssSkin !== "") {this.sDataTable.className += " " + this.cssSkin + "-Main";this.sHeaderTable.className += " " + this.cssSkin + "-Headers";if (this.fixedCols > 0) {this.sFDataTable.className += " " + this.cssSkin + "-Fixed";this.sFHeaderTable.className += " " + this.cssSkin + "-FixedHeaders";}}/* Throw everything into sBase */if (this.fixedCols > 0) {this.sBase.appendChild(this.sFHeader);}this.sHeader.appendChild(this.sHeaderInner);this.sBase.appendChild(this.sHeader);if (this.fixedCols > 0) {this.sFData.appendChild(this.sFDataInner);this.sBase.appendChild(this.sFData);}this.sBase.appendChild(this.sData);this.sParent.insertBefore(this.sBase, this.sDataTable);this.sData.appendChild(this.sDataTable);/* Align the tables */var sDataStyles, sDataTableStyles;this.sHeaderHeight = this.sDataTable.tBodies[0].rows[(this.sDataTable.tHead) ? 0 : this.headerRows].offsetTop;sDataTableStyles = "margin-top: " + (this.sHeaderHeight * -1) + "px;";sDataStyles = "margin-top: " + this.sHeaderHeight + "px;";sDataStyles += "height: " + (this.sParentHeight - this.sHeaderHeight) + "px;";if (this.fixedCols > 0) {		/* A collapsed table's cell's offsetLeft is calculated differently (w/ or w/out border included) across broswers - adjust: */this.sFHeaderWidth = this.sDataTable.tBodies[0].rows[cleanRow].cells[this.fixedCols].offsetLeft;if (window.getComputedStyle) {alpha = document.defaultView;beta = this.sDataTable.tBodies[0].rows[0].cells[0];if (navigator.taintEnabled) { /* If not Safari */this.sFHeaderWidth += Math.ceil(parseInt(alpha.getComputedStyle(beta, null).getPropertyValue("border-right-width")) / 2);} else {this.sFHeaderWidth += parseInt(alpha.getComputedStyle(beta, null).getPropertyValue("border-right-width"));}} else if (/*@cc_on!@*/0) { /* Internet Explorer */alpha = this.sDataTable.tBodies[0].rows[0].cells[0];beta = [alpha.currentStyle["borderRightWidth"], alpha.currentStyle["borderLeftWidth"]];if(/px/i.test(beta[0]) && /px/i.test(beta[1])) {beta = [parseInt(beta[0]), parseInt(beta[1])].sort();this.sFHeaderWidth += Math.ceil(parseInt(beta[1]) / 2);}}/* Opera 9.5 issue - a sizeable data table may cause the document scrollbars to appear without this: */if (window.opera) {this.sFData.style.height = this.sParentHeight + "px";}this.sFHeader.style.width = this.sFHeaderWidth + "px";sDataTableStyles += "margin-left: " + (this.sFHeaderWidth * -1) + "px;";sDataStyles += "margin-left: " + this.sFHeaderWidth + "px;";sDataStyles += "width: " + (this.sParentWidth - this.sFHeaderWidth) + "px;";} else {sDataStyles += "width: " + this.sParentWidth + "px;";}this.sData.style.cssText = sDataStyles;this.sDataTable.style.cssText = sDataTableStyles;/* Set up table scrolling and IE's onunload event for garbage collection */(function (st) {if (st.fixedCols > 0) {st.sData.onscroll = function () {st.sHeaderInner.style.right = st.sData.scrollLeft + "px";st.sFDataInner.style.top = (st.sData.scrollTop * -1) + "px";};} else {st.sData.onscroll = function () {st.sHeaderInner.style.right = st.sData.scrollLeft + "px";};}if (/*@cc_on!@*/0) { /* Internet Explorer */window.attachEvent("onunload", function () {st.sData.onscroll = null;st = null;});}})(this);this.callbackFunc && this.callbackFunc();
};

3.jquery.superTable.js

/
// Super Tables Plugin for jQuery - MIT Style License
// Copyright (c) 2009 Jeffrey Lee --- blog.darkthread.net
//
// A wrapper for Matt Murphy's Super Tables http://www.matts411.com/post/super_tables/
//
// Contributors:
//
/
// TO CALL: 
// $("...").toSuperTable(options)
//
// OPTIONS: (order does not matter )
// cssSkin : string ( eg. "sDefault", "sSky", "sOrange", "sDark" )
// headerRows : integer ( default is 1 )
// fixedCols : integer ( default is 0 )
// colWidths : integer array ( use -1 for auto sizing )
// onStart : function ( any this.variableNameHere variables you create here can be used later ( eg. onFinish function ) )
// onFinish : function ( all this.variableNameHere variables created in this script can be used in this function )
// margin, padding, width, height, overflow...: Styles for "fakeContainer"
//
// Example:
// $("#GridView1").toSuperTable(
//              { width: "640px", height: "480px", fixedCols: 2,
//                onFinish: function() { alert('Done!'); } })(function($) {$.fn.extend({toSuperTable: function(options) {var setting = $.extend({width: "640px", height: "320px",margin: "10px", padding: "0px",overflow: "hidden", colWidths: undefined,fixedCols: 0, headerRows: 1,onStart: function() { },onFinish: function() { },cssSkin: "sSky"}, options);return this.each(function() {var q = $(this);var id = q.attr("id");q.removeAttr("style").wrap("<div id='" + id + "_box'></div>");var nonCssProps = ["fixedCols", "headerRows", "onStart", "onFinish", "cssSkin", "colWidths"];var container = $("#" + id + "_box");for (var p in setting) {if ($.inArray(p, nonCssProps) == -1) {container.css(p, setting[p]);delete setting[p];}}var mySt = new superTable(id, setting);});}});
})(jQuery);

4.use:

<link href="superTables.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="jquery-1.3.1.js"></script><script type="text/javascript" src="superTables.js"></script><script type="text/javascript" src="jquery.superTable.js"></script><script type="text/javascript">$(function() {$("#GridView1").toSuperTable({ width: "640px", height: "480px", fixedCols: 2 }).find("tr:even").addClass("altRow");});</script>

 

5其它方法参考

http://www.cnblogs.com/yougewe/p/5484251.html

http://www.cnblogs.com/kenshincui/archive/2011/03/30/1999625.html

转载于:https://my.oschina.net/zuoan001/blog/738569

这篇关于js固定表头或者表列(2) jquery.superTable.js的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/266762

相关文章

Vue3 的 shallowRef 和 shallowReactive:优化性能

大家对 Vue3 的 ref 和 reactive 都很熟悉,那么对 shallowRef 和 shallowReactive 是否了解呢? 在编程和数据结构中,“shallow”(浅层)通常指对数据结构的最外层进行操作,而不递归地处理其内部或嵌套的数据。这种处理方式关注的是数据结构的第一层属性或元素,而忽略更深层次的嵌套内容。 1. 浅层与深层的对比 1.1 浅层(Shallow) 定义

JS常用组件收集

收集了一些平时遇到的前端比较优秀的组件,方便以后开发的时候查找!!! 函数工具: Lodash 页面固定: stickUp、jQuery.Pin 轮播: unslider、swiper 开关: switch 复选框: icheck 气泡: grumble 隐藏元素: Headroom

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

【 html+css 绚丽Loading 】000046 三才归元阵

前言:哈喽,大家好,今天给大家分享html+css 绚丽Loading!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 📚一、效果📚二、信息💡1.简介:💡2.外观描述:💡3.使用方式:💡4.战斗方式:💡5.提升:💡6.传说: 📚三、源代码,上代码,可以直接复制使用🎥效果🗂️目录✍️

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

在JS中的设计模式的单例模式、策略模式、代理模式、原型模式浅讲

1. 单例模式(Singleton Pattern) 确保一个类只有一个实例,并提供一个全局访问点。 示例代码: class Singleton {constructor() {if (Singleton.instance) {return Singleton.instance;}Singleton.instance = this;this.data = [];}addData(value)

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能

Vue3项目开发——新闻发布管理系统(六)

文章目录 八、首页设计开发1、页面设计2、登录访问拦截实现3、用户基本信息显示①封装用户基本信息获取接口②用户基本信息存储③用户基本信息调用④用户基本信息动态渲染 4、退出功能实现①注册点击事件②添加退出功能③数据清理 5、代码下载 八、首页设计开发 登录成功后,系统就进入了首页。接下来,也就进行首页的开发了。 1、页面设计 系统页面主要分为三部分,左侧为系统的菜单栏,右侧

Node.js学习记录(二)

目录 一、express 1、初识express 2、安装express 3、创建并启动web服务器 4、监听 GET&POST 请求、响应内容给客户端 5、获取URL中携带的查询参数 6、获取URL中动态参数 7、静态资源托管 二、工具nodemon 三、express路由 1、express中路由 2、路由的匹配 3、路由模块化 4、路由模块添加前缀 四、中间件

【VUE】跨域问题的概念,以及解决方法。

目录 1.跨域概念 2.解决方法 2.1 配置网络请求代理 2.2 使用@CrossOrigin 注解 2.3 通过配置文件实现跨域 2.4 添加 CorsWebFilter 来解决跨域问题 1.跨域概念 跨域问题是由于浏览器实施了同源策略,该策略要求请求的域名、协议和端口必须与提供资源的服务相同。如果不相同,则需要服务器显式地允许这种跨域请求。一般在springbo