[轉帖][強烈推薦]網頁表格(Table/GridView)標題欄和列凍結(跨瀏覽器兼容)

GridView的標題欄、列凍結效果(跨瀏覽器版)

本文來源:http://blog.darkthread.net/blogs/darkthreadtw/archive/2009/02/18/supertable-plugin-for-jquery.aspx

稍早發表了GridView 的標題列凍結效果,足以滿足工作上的需求,不過存在兩個缺點:只支援FF及IE6/7、只能凍結列不能凍結欄(行)...

不甘心事情只做一半,又挖了一下,驚喜地發現另一個版本: Super Tables,可以支援 Firefox 2+, Internet Explorer 5.5+, Safari 3+, Opera 9+以及Chrome,而且也支援直欄的凍結效果,在功能上大勝ScrollableTable,二話不說,通通包起來。

SuperTable的原理與ScrollableTable不同,它需要額外的CSS以及在Table外包一層<div>,可視范圍 大小由<div> Style決定,設定時參數也較多(如:fixedCols, headerRows...),所以我寫了一個jQuery Plugin(jquery.superTable.js)把它包起來。有了Plugin的加持,只要一個toSuperTable(options)就 可立即升級成有凍結效果的GridView了。

排版顯示純文字復制文字
/
// 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);

完整的Demo程式如下:

排版顯示純文字復制文字
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
DataTable t = new DataTable();
t.Columns.Add("序號", typeof(int));
t.Columns.Add("料號", typeof(string));
t.Columns.Add("單價", typeof(decimal));
for (int i = 1; i <= 10; i++)
t.Columns.Add("庫存" + i, typeof(int));
Random rnd = new Random();
for (int i = 0; i < 80; i++)
{
DataRow row = t.NewRow();
row["序號"] = i + 1;
row["料號"] = Guid.NewGuid().ToString().Substring(0, 13).ToUpper();
row["單價"] = rnd.NextDouble() * 100;
for (int j = 1; j <= 10; j++)
row["庫存" + j] = rnd.Next(10000);
t.Rows.Add(row);
}
GridView1.AutoGenerateColumns = false;
foreach (DataColumn c in t.Columns)
{
BoundField bf = new BoundField();
bf.DataField = c.ColumnName;
bf.HeaderText = c.ColumnName;
if (c.DataType == typeof(decimal))
bf.DataFormatString = "{0:#,0.00}";
else if (c.DataType == typeof(int))
bf.DataFormatString = "{0:#,0}";
bf.ItemStyle.HorizontalAlign =
(!string.IsNullOrEmpty(bf.DataFormatString)) ?
HorizontalAlign.Right : HorizontalAlign.Center;
 
GridView1.Columns.Add(bf);
}
GridView1.DataSource = t;
GridView1.DataBind();
}
</script>
?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.altRow { background-color: #ddddff; }
</style>
<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>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" Font-Size="9pt" EnableViewState="false">
</asp:GridView>
</form>
</body>
</html>

我放了一個線上Demo在http://www.darkthread.net/MiniAjaxLab/ScrollTable ,或者你也可以下載程 式包回去玩。

轉載于:https://www.cnblogs.com/aaa6818162/archive/2012/01/12/2320795.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377834.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377834.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377834.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

psu是什么電腦配件_PSU的完整形式是什么?

psu是什么電腦配件PSU&#xff1a;電源部門/公共部門事業 (PSU: Power Supply Unit / Public Sector Undertaking) 1)PSU&#xff1a;電源設備 (1) PSU: Power Supply Unit) PSU is an abbreviation of the "Power Supply Unit". PSU是“電源設備”的縮寫 。 It is a…

【C++grammar】斷言與表達式常量

目錄1、常量表達式和constexpr關鍵字2、斷言與C11的靜態斷言1.1. assert : C語言的宏(Macro)&#xff0c;運行時檢測。1.2. assert()依賴于NDEBUG 宏1.3. assert 幫助調試解決邏輯bug &#xff08;部分替代“斷點/單步調試”&#xff09;2.1static_assert (C11的靜態斷言 )2.2.…

一些又用的國內著名期刊

記&#xff1a; 電子學報、電子與信息學報、圖像圖形學報、自動化學報、計算機學報、軟件學報、計算機研究與發展。轉載于:https://www.cnblogs.com/nanyangzp/p/3322244.html

一、Arduino UNO R3將數據上傳至云平臺

一、準備工作 ①ESP12E Shield ②Arduino UNO R3開發板 ③把ESP12E Shield安裝到Arduino UNO R3開發板上 ④登錄物聯網平臺注冊個賬號&#xff0c;到時候需要使用。 ⑤記錄下來你的Uid和key到時候會用到 ⑥創建個設備&#xff0c;用于測試 ⑦beyondyanyu為設備名&…

怎樣做一個快樂的ASP.NET程序員

首先我想解釋一下標題中兩個關鍵字: "快樂", "ASP.NET程序員". 有的人想成為一個"杰出"的程序員, 或者"資深"的程序員, 簡單來說就是"大牛"級的人物 -- 但是本文不是針對此種發展方向不是說我不鼓勵大家朝這方向走, 而是對我…

__eq___C ++'and_eq'關鍵字和示例

__eq__"and_eq" is an inbuilt keyword that has been around since at least C98. It is an alternative to & (Bitwise AND Assignment) operator and it mostly uses for bit manipulations. “ and_eq”是一個內置關鍵字&#xff0c;至少從C 98起就存在。 它…

leetcode 93. 復原IP地址 思考分析

題目 給定一個只包含數字的字符串&#xff0c;復原它并返回所有可能的 IP 地址格式。 有效的 IP 地址 正好由四個整數&#xff08;每個整數位于 0 到 255之間組成&#xff0c;且不能含有前導 0&#xff09;&#xff0c;整數之間用 ‘.’ 分隔。 例如&#xff1a;“0.1.2.201” …

二、通過云平臺反向控制Arduino UNO R3

該篇博文是在第一篇博文(一、Arduino UNO R3將數據上傳至云平臺)的基礎上進行的 一、云平臺發送指令反向控制Arduino UNO R3 ESP12E Shield開關都推到OFF&#xff08;要不然下載會報錯&#xff09;&#xff0c;往Arduino UNO R3開發板上下載下面的代碼 這段代碼進行測試要點&…

使用MSBuild編譯FsLex項目

FsLex FsYacc微軟本身也提供了一個項目模板。但是這個項目模板是lex和yacc文件均包含。我想只適用lex&#xff0c;但是如果每次使用命令行也覺得不夠方便&#xff0c;于是還是研究了一番MsBuild的使用。 使用msbuild hellp.fsproj /v:d 可以查看整個msbuild的流程&#xff0c;非…

Python字符串格式:%vs.format

Often the string formatters in python are referred to as old style and new style. The old-style is % and .format is known as the new style. python中的字符串格式化程序通常被稱為舊樣式和新樣式。 舊樣式為&#xff05; &#xff0c;. format被稱為新樣式。 Simple…

【C++grammar】代理構造、不可變對象、靜態成員

目錄1、Delegation Constructor&#xff08;代理構造&#xff09;1. What is delegating constructor? (什么是代理構造/委托構造)2. Avoiding recursive calls of target constructors (避免遞歸調用目標ctor)3. 委托構造的好處2、不可變對象和類1、如何讓類成為“不可變類”…

paip.最新的c++ qt5.1.1環境搭建跟hello world

paip.最新的c qt5.1.1環境搭建跟hello world 作者Attilax &#xff0c; EMAIL:1466519819qq.com 來源&#xff1a;attilax的專欄 地址&#xff1a;http://blog.csdn.net/attilax 有一段時間沒接觸c了...今天下載新的qt下來研究一番.. qt的環境搭建有eclipseqtdtmingwqtl…

RFID模塊+WIFI模塊+振動傳感器+有源蜂鳴器+舵機+Arduino UNO R3所構成的門禁系統模塊

該系統模塊主要由RFID模塊WIFI模塊振動傳感器有源蜂鳴器舵機Arduino UNO R3組成的門禁系統模塊。這里使用舵機充當門鎖&#xff0c;用戶可以刷卡開門&#xff0c;也可以通過APP控制舵機狀態達到開門的效果。若有不法分子想要強行進入室內&#xff0c;對門進行撞擊或者人為的破壞…

PushManager

http://suchandalex.googlecode.com/svn/trunk/beOui/beWe/client/Classes/PushNotificationManager.m轉載于:https://www.cnblogs.com/vincent-lu/archive/2012/01/18/2325740.html

krsort_PHP krsort()函數與示例

krsortPHP krsort()函數 (PHP krsort() function) krsort() function is used to sort an associative array in descending order based on the keys, as we know that an associative array contains keys and values, this method sorts an array according to the keys. kr…

ESP12E Shield+Arduino UNO R3開發板+DHT11溫濕度模塊+雙色LED燈+有源蜂鳴器+光敏電阻模塊+I2CLCD1602液晶顯示器所構成的室內檢測系統

室內檢測系統由ESP12E ShieldArduino UNO R3開發板DHT11溫濕度模塊雙色LED燈有源蜂鳴器光敏電阻模塊I2CLCD1602液晶顯示器所構成。DHT11溫濕度模塊獲取室內溫濕度數據通過I2CLCD1602液晶顯示器進行顯示&#xff0c;另一方面通過ESP12E Shield將數據上傳至云平臺。光敏電阻進行捕…

輸入輸出函數:

一、printf函數&#xff1a;     printf("Hello World!\n");     printf("My age is %d\n",26);     int age 17;     printf("My age is %d\n",age);  %d 或 %i: 帶符號 十進制整數。   %o:不帶符號 八進制整數。   %x:…

leetcode 202. 快樂數 思考分析(哈希集合與雙指針解)

1、題目 編寫一個算法來判斷一個數 n 是不是快樂數。 「快樂數」定義為&#xff1a;對于一個正整數&#xff0c;每一次將該數替換為它每個位置上的數字的平方和&#xff0c;然后重復這個過程直到這個數變為 1&#xff0c;也可能是 無限循環 但始終變不到 1。如果 可以變為 1&am…

五、線性回歸和多項式回歸實現

官網API 一、線性回歸 針對的是損失函數loss faction Ⅰ、Lasso Regression 采用L1正則&#xff0c;會使得w值整體偏小&#xff1b;w會變小從而達到降維的目的 import numpy as np from sklearn.linear_model import Lasso from sklearn.linear_model import SGDRegresso…

JavaScript中的地圖與對象

JavaScript對象與地圖 (JavaScript Objects vs Maps) Objects are super popular in JavaScript so its not a term you are hearing for the first time even if youre a novice JS developer. Objects, in general, are a very common data structure that is used very ofte…