其实这些功能在PL/SQL Dev中都有实现,在页面中还是蛮常见的。

我实现列的单向固定的原理:将需要单向固定的列放在一个<table>标签中,而整体的数据放在另一个<table>标签中。

列的拖拽:使用onstartdrag、ondragover、drop事件

 <!DOCTYPE HTML>
<html>
<head>
<title>table拖拽与行列固定</title>
<script src="jquery1.11.3.js"></script>
<style>
#big_div {
position: absolute;
background: white;
WIDTH: 700px;
height: 500px;
overflow-y: auto;
overflow-x: scroll;
border: black 1px solid;
z-index: 1;
} #table_total {
WIDTH: 900px;
} #div_head_cloumn {
position: absolute;
z-index: 100;
background: yellow;
border-top: 1px solid black;
border-left: 1px solid black;
border-right: 0px solid black;
border-bottom: 0px solid black;
} #div_head {
position: absolute;
z-index: 10;
background: #C0C0C0;
border-top: 1px solid black;
border-left: 1px solid black;
border-right: 0px solid black;
border-bottom: 0px solid black;
overflow: hidden;
} #table_head {
position: absolute;
width: 900px;
} #div_column {
position: absolute;
z-index: 50;
background1: white;
background: #93DB70;
border-top: 1px solid black;
border-left: 1px solid black;
border-right: 0px solid black;
border-bottom: 0px solid black;
overflow: hidden;
border-left: 1px solid black;
border-right: 0px solid black;
border-bottom: 0px solid black;
border-right: 0px solid black;
border-bottom: 0px solid black;
border-bottom: 0px solid black;
} #Vscrollable {
position: absolute;
}
</style>
</head>
<body>
<div id="div_head_cloumn">
<table id="table_head_cloumn">
<tr>
<th id="th_head_cloumn" class="fixed">FX_ID</th>
</tr>
</table>
</div> <div id="div_head">
<table id="table_head">
<tr id="tr_table_head">
<th id="head_th1" class="index_1">FX_ID</th>
<th id="head_th2" class="index_2">FX_MC</th>
<th id="head_th3" class="index_3">FX_DM</th>
<th id="head_th4" class="index_4">NSRSBM</th>
<th id="head_th5" class="index_5">NSR_MC</th>
</tr>
</table>
</div> <div id="div_column">
<table id="Vscrollable">
<tr>
<th>FX_ID</th>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
<tr>
<td>5160DFE2DE97BF89E053065B0C8D785F</td>
</tr>
</table>
</div>
<div>ssss</div>
<div id="big_div" onscroll="onscroll_function()">
<table id="table_total"> <tr id="tr_th" class="transform">
<th id="th1" class="index_1">FX_ID</th>
<th id="th2" class="index_2">FX_MC</th>
<th id="th3" class="index_3">FX_DM</th>
<th id="th4" class="index_4">NSRSBM</th>
<th id="th5" class="index_5">NSR_MC</th>
</tr> <tr id="tr_td_1" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资、合伙企业个人所得税汇缴年报表收入总额小于国税财务报表营业收入风险指标</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">91320104MA1MMKK006</td>
<td class="index_5">南京月凌舞文化艺术培训中心</td>
</tr>
<tr id="tr_td_2" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">913201147568649920</td>
<td class="index_5">南京中太</td>
</tr>
<tr id="tr_td_3" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资、合伙企业个人所得税汇缴年报表收入总额小于国税财务报表营业收入风险指标</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">320103738870483</td>
<td class="index_5">南京中宁制冷空调技术服务中心</td>
</tr>
<tr id="tr_td_4" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资、合伙企业个人所得税汇缴年报表收入总额小于国税财务报表营业收入风险指标</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">91320104MA1MMKK006</td>
<td class="index_5">南京月凌舞文化艺术培训中心</td>
</tr>
<tr id="tr_td_5" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资、合伙企业个人所得税汇缴年报表收入总额小于国税财务报表营业收入风险指标</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">91320104MA1MMKK006</td>
<td class="index_5">南京月凌舞文化艺术培训中心</td>
</tr>
<tr id="tr_td_6" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资、合伙企业个人所得税汇缴年报表收入总额小于国税财务报表营业收入风险指标</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">91320104MA1MMKK006</td>
<td class="index_5">南京月凌舞文化艺术培训中心</td>
</tr>
<tr id="tr_td_7" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资、合伙企业个人所得税汇缴年报表收入总额小于国税财务报表营业收入风险指标</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">91320104MA1MMKK006</td>
<td class="index_5">南京月凌舞文化艺术培训中心</td>
</tr>
<tr id="tr_td_8" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资、合伙企业个人所得税汇缴年报表收入总额小于国税财务报表营业收入风险指标</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">91320104MA1MMKK006</td>
<td class="index_5">南京月凌舞文化艺术培训中心</td>
</tr>
<tr id="tr_td_9" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资、合伙企业个人所得税汇缴年报表收入总额小于国税财务报表营业收入风险指标</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">91320104MA1MMKK006</td>
<td class="index_5">南京月凌舞文化艺术培训中心</td>
</tr>
<tr id="tr_td_10" class="transform">
<td class="index_1">5160DFE2DE97BF89E053065B0C8D785F</td>
<td class="index_2">(省局第三方)个人独资、合伙企业个人所得税汇缴年报表收入总额小于国税财务报表营业收入风险指标</td>
<td class="index_3">320010ZB00001139</td>
<td class="index_4">91320104MA1MMKK006</td>
<td class="index_5">南京月凌舞文化艺术培训中心</td>
</tr>
</table>
</div> <p id="demo"></p>
<script>
//alert(getScrollBarWidth());
/*设置head_cloumn的位置和大小,jquery中css()方法设置样式*/
$("#div_head_cloumn").css("top",$("#big_div").offset().top).css("left",$("#big_div").offset().left);
$("#div_head_cloumn").css("height",$("#tr_th").height()+$("#tr_th").offset().top-$("#big_div").offset().top);
$("#div_head_cloumn").css("width",$("#th1").width()+$("#th1").offset().left-$("#big_div").offset().left);
$("#table_head_cloumn").css("height",$("#tr_th").height()+$("#tr_th").offset().top-$("#big_div").offset().top-2);//table 与div间隔1 absoulte属性会是div大小随内容被撑开
$("#table_head_cloumn").css("width",$("#th1").width()+$("#th1").offset().left-$("#big_div").offset().left-2);//thead+1,tr+1,th+1 /*设置head的位置和大小 并设置其中每个th的大小*/
$("#div_head").css("top",$("#big_div").offset().top).css("left",$("#big_div").offset().left);
$("#div_head").css("height",$("#tr_th").height()+$("#tr_th").offset().top-$("#big_div").offset().top);
$("#div_head").css("width",700-getScrollBarWidth());//没有特殊设置的话滚动条宽度固定为16px
//$("#table_head").css("height",$("#tr_th").height()+$("#tr_th").offset().top-$("#big_div").offset().top-2);
//$("#table_head").css("width",$("#tr_th").width()+684);//thead+1,tr+1,th+1
$("#table_head th").each(function(index1, element1) {//利用each循环(jquery中的方法)将各个th的宽度设置好
$("#big_div th").each(function(index2, element2) {
if($(element2).attr("id")==("th"+(index1+1))){//jquery中attr()方法设置属性
$(element1).css("width",$(element2).css("width"));
return false;
}
});
}); /*设置cloumn的位置和大小 并设置其中每个tr的大小*/
$("#div_column").css("top",$("#big_div").offset().top).css("left",$("#big_div").offset().left);
$("#div_column").css("height",$("#big_div").height()-getScrollBarWidth());
$("#div_column").css("width",$("#th1").width()+$("#th1").offset().left-$("#big_div").offset().left);
$("#Vscrollable").css("height",$("#table_total").height());
$("#Vscrollable").css("width",$("#th1").width()+$("#th1").offset().left-$("#big_div").offset().left-2);
$("#Vscrollable tr:first").css("height",$("#tr_th").css("height"));
$("#Vscrollable tr").each(function(index1, element1) {//同样利用each将各个tr的高度设置好
if(index1==0){
return true;
}
$("#big_div tr").each(function(index2, element2) {
if($(element2).attr("id")==("tr_td_"+index1)){
$(element1).css("height",$(element2).css("height"));
return false;
}
});
});
//$("#Vscrollable tr").css("height",$("#tr_td_1").css("height"));
//$("#Vscrollable tr:first").css("height",$("#tr_th").css("height")); /*单向固定的方法,逻辑:实时传递大div的滚动条位置给小div的滚动条(小div的滚动条是隐藏的)*/
function onscroll_function() {
document.getElementById("table_head").style.left = document
.getElementById("big_div").scrollLeft
* -1 + 'px';
document.getElementById("Vscrollable").style.top = document
.getElementById("big_div").scrollTop
* -1 + 'px';
} /*----------------------------------------------------------------*/ //获得滚动条宽的
function getScrollBarWidth() {
var inner = document.createElement('p');
inner.style.width = "100%";
inner.style.height = "200px"; var outer = document.createElement('div');
outer.style.position = "absolute";
outer.style.top = "0px";
outer.style.left = "0px";
outer.style.visibility = "hidden";
outer.style.width = "200px";
outer.style.height = "150px";
outer.style.overflow = "hidden";
outer.appendChild (inner); document.body.appendChild (outer);
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
var w2 = inner.offsetWidth;
if (w1 == w2) w2 = outer.clientWidth; document.body.removeChild (outer); return (w1 - w2);
} var _target;//拖拽的元素//声明变量
var _droptarget;//触发drop事件的元素
var end_X = 0;//drop时鼠标位置
var end_Y = 0;
var e_left = 0;//触发drop事件的元素的位置(绝对)
var e_width = 0;//触发drop事件的元素的宽度
var ifFixed = false;//是否被固定
var first_cell = $("#head_th1");//第一个单元格
var first_cell_class = $(first_cell).attr("class");//第一个单元格的class
$("th").attr("draggable",true);//attr设置属性css设置样式
var width_balance = $("#th1").offset().left-$("#big_div").offset().left;//宽度差额 //设置鼠标在id为"sortable1"的元素上时的样式为"move"
document.getElementById("tr_th").style.cursor = "move";
document.getElementById("div_head_cloumn").style.cursor = "move";
document.getElementById("div_head").style.cursor = "move"; //jquery绑定方法,当p发生dragstart事件时触发此方法
$('th').on('dragstart',function(e){
_target = e.target;
//如果拖拽的元素是固定的列,就把固定列下面的活动的列赋值给_target
if($(e.target).attr("class")=="fixed"){
ifFixed = true;
_target = first_cell;
}
}); //jquery绑定方法,当p发生dragover事件时触发此方法
$('th').on('dragover',function(e){
e.preventDefault();//该方法将通知 Web 浏览器不要执行与事件关联的默认动作(如果存在这样的动作)
}); //jquery绑定方法,当p发生drop事件时触发此方法
$('th').on('drop',function(e){
event.preventDefault();
_droptarget = event.srcElement;//获得事件的源对象
if($(_droptarget).attr("class")=="fixed"){
ifFixed = true;
_droptarget = first_cell;
}
end_X = event.pageX;
end_Y = event.pageY;
e_left = $(_droptarget).offset().left;
e_width = $(_droptarget).width(); if ($(_droptarget).attr("draggable") == "true") {//draggable属性,为true时可拖拽,false时不可拖拽
if (end_X<(e_left+e_width/2))
$(_droptarget).before($(_target));//before方法 语法$(selector).before(content);将content添加到选定的元素之前
if (end_X>=(e_left+e_width/2))
$(_droptarget).after($(_target));//after()方法
} var arrayObj_th = new Array();//创建一个数组 $("#tr_table_head>th").each(function() {//each遍历
arrayObj_th.push($(this));//push数组的添加元素操作
}); //alert($("#tr_td_1 td").size());
$(".transform").each(function(index1, element1) {
var arrayObj_td = new Array();
var arrayObj_td_temp = new Array();
// alert(index1);
for(var i=1;i<=arrayObj_th.length;i++){
arrayObj_td_temp.push($(this).children(".index_"+i));
} $.each(arrayObj_th, function (index, item) {
$.each(arrayObj_td_temp, function (index2, item2) {//index2:下标、item2:元素(Object)
//attr获取/设置元素的属性值
if(item.attr("class")==item2.attr("class")){//元素.attr("class")获取该元素的class值
arrayObj_td.push(item2);}
});
}); for(var i=arrayObj_td.length-1;i>=0;i--){
arrayObj_td[i].before(arrayObj_td[i-1]);
}
});
if(ifFixed==true){//如果拖拽的元素是固定的列,改变固定列的大小、文本内容
ifFixed=false;
first_cell = arrayObj_th[0];
first_cell_class = $(first_cell).attr("class");
$("#div_head_cloumn").css("width",$(first_cell).width()+width_balance);
$("#table_head_cloumn").css("width",$(first_cell).width()+width_balance-2);//thead+1,tr+1,th+1
$("#th_head_cloumn").text($(first_cell).text()); $("#div_column").css("width",$(first_cell).width()+width_balance);
$("#Vscrollable").css("width",$(first_cell).width()+width_balance-2);
//$("#Vscrollable tr").css("height",$("#tr_td_1").css("height"));
//$("#Vscrollable tr:first").css("height",$("#tr_th").css("height")); $("#table_total ."+first_cell_class).each(function(index, element) {
if($(element).attr("class")==first_cell_class){
$("#Vscrollable th,td").eq(index).text($(element).text());
}
});
}
});
</script>
</body>
</html>

jquery实现行列的单向固定和列的拖拽的更多相关文章

  1. 前端笔记之jQuery(下)事件&节点操作&净位置&拖拽&页面卷动值&遍历JSON

    一.监听事件大全 1.1 JavaScript事件 onblur 元素失去焦点 onchange 用户改变域的内容 onclick 鼠标点击某个对象 ondblclick 鼠标双击某个对象 onfoc ...

  2. jquery监听事件on写法以及简单的拖拽效果

    引子——关于jquery的某些写法 我先不对监听事件做解释,我们先来看下jquery的一些写法吧!我们最常用的是jquery的css()方法,相信大家都会用! 假如用css设置一个属性,我们写法如下: ...

  3. 原生js实现 table表格列宽拖拽

    查看效果 <!DOCTYPE html> <html> <head> <meta charset="gbk"> <title& ...

  4. 关于js在一个固定的盒子里面拖拽的问题(包含临界值)

    回武汉打卡第三天,武汉加油,逆战必胜!今天我们一起分享一下js拖拽的问题. 当然实现拖拽方法是有很多的,下面简单讲一种方法,大致思路如下: 首先需要用到的事件主要有  onmousedown,onmo ...

  5. jquery插件之拖拽改变元素大小

    该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的拖拽改变元素大小的效果,您可以根据自己的实际需求来设置被 ...

  6. jquery插件之拖拽

    该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的拖拽效果,您可以根据自己的实际需求来设置被拖拽元素是否可 ...

  7. jquery隐藏table表格的某一列

    jquery隐藏table表格的某一列: $('table tr').find('td:eq(13)').hide(); 隐藏table的第13列

  8. jQuery&CSS 顶部和底部固定浮动工具栏 兼容IE6

    http://www.cnblogs.com/lhj588/archive/2013/04/02/2994639.html —————————————————————————————————————— ...

  9. 固定标题列、标题头table

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. unix网络编程——TCP套接字编程

    TCP客户端和服务端所需的基本套接字.服务器先启动,之后的某个时刻客户端启动并试图连接到服务器.之后客户端向服务器发送请求,服务器处理请求,并给客户端一个响应.该过程一直持续下去,直到客户端关闭,给服 ...

  2. python学习笔记05:贪吃蛇游戏代码

    贪吃蛇游戏截图: 首先安装pygame,可以使用pip安装pygame: pip install pygame 运行以下代码即可: #!/usr/bin/env python import pygam ...

  3. 16_常用API_第16天(正则表达式、Date、DateFormat、Calendar)_讲义

    今日内容介绍 1.正则表达式的定义及使用 2.Date类的用法 3.Calendar类的用法 ==========================================第一阶段======= ...

  4. 51单片机RAM 数据存储区学习笔记

    转自:http://www.eepw.com.cn/article/216237_2.htm 1.RAM keil C语言编程 RAM是程序运行中存放随机变量的数据空间.在keil中编写程序,如果当前 ...

  5. 个人作业-week3案例分析

    第一部分 软件调研测评(必应词典移动端) 找到的bug: 在词汇量测试中每个单词给用户思考的时间太短,只有五秒钟.导致很多似曾相识的单词还没来得及想起就已经过了.如果说测的是用户记忆深刻的单词,那些记 ...

  6. 总结MySQL修改最大连接数的两个方式

    最大连接数是可以通过mysql进行修改的,mysql数据库修改最大连接数常用有两种方法,今天我们分析一下这两种方法之间的特点和区别,以便我们能更好的去维护mysql.下面我们来看一下mysql修改最大 ...

  7. pygame入门

    pygame入门 说明 在学习pygame时,主要参考了目光博客的教程.目光博客 原教程是2011年写的,年代比较久远了,使用Python2.我学习时使用python3将代码重新实现了一遍,同时补充了 ...

  8. [转帖] IIS 与 HTTP/2 的介绍.

    HTTP/2 on IIS https://blogs.iis.net/davidso/http2 Friday, September 11, 2015 Windows 10 HTTP2 In Oct ...

  9. java异常处理的throw和throws的区别

    1. 区别 throws是用来声明一个方法可能抛出的所有异常信息,throws是将异常声明但是不处理,而是将异常往上传,谁调用我就交给谁处理.而throw则是指抛出的一个具体的异常类型. 2.分别介绍 ...

  10. 【转载】css3动画简介以及动画库animate.css的使用

    原文地址:http://www.cnblogs.com/2050/p/3409129.html 在这个年代,你要是不懂一点点css3的知识,你都不好意思说你是个美工.美你妹啊,请叫我前端工程师好不好. ...