其实这些功能在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. 2018软工实践—Beta冲刺(2)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Beta 冲鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调组内工作 修改前端界面 展示GitHub当日代码/文档签入记录(组内 ...

  2. caffe with anaconda

    https://blog.csdn.net/u013498583/article/details/74231058 https://www.cnblogs.com/youxin/p/4073703.h ...

  3. linux下使用pip在虚拟环境下安装tensorflow-gpu

    1. 查看已安装包库 pip list 2. linux下下载虚拟环境 sudo apt-get install python-virtualenv 3.建立全新的virtualenv环境 virtu ...

  4. visualStudo编译c程序, 提示函数unSafe问题

    问题描述: 在利用visualStudo进行C语言编程时,若C语言源程序中有print,freopen等函数时,IDE软件总是unSafe,而且无法通过编译. 解决方案: 在<视图>中找到 ...

  5. HighCharts点击柱形或饼块等加URL或Click事件

    我们在做图表的时候,有时候需要在单个数据上加链接或点击事件,是在plotOptions里的events里设置的: 如下代码: plotOptions: { pie: { cursor: 'pointe ...

  6. 最新版ABP 动态WebAPI 日期转json带T的解决方案| ABP DateTIme Json format

    ABP动态webapi返回的json数据中,日期时间带T还有毫秒数的问题,在以往的版本中可以使用下面方法解决: 在XXXAbpWebApiModule中加上下面的代码: 很老的很老的版本有效: pub ...

  7. 预则立&&他山之石--团队计划、访谈优秀前辈

    团队计划&访谈内容 一.团队计划 序号 任务内容 计划完成时间 主要负责人 备注 1 对接教师报课系统 决定是否重构代码 2016.10.16 陈少铭.黄家俊 阅读CourseManageme ...

  8. Git命令提交项目代码

    Git客户端安装 今天就结合`GitHub`,通过`Git`命令,来了解如何实现开源代码库以及版本控制 GitHub是一个面向开源及私有软件项目的托管平台,因为只支持Git 作为唯一的版本库格式进行托 ...

  9. php htmlentities和htmlspecialchars 的区别

    很多人都以为htmlentities跟htmlspecialchars的功能是一样的,都是格式化html代码的,我以前也曾这么认为,但是今天我发现并不是这样的.   The translations ...

  10. 查看ROS最大并发连接数量

    命令行下输入以下 ip firewall connection tracking print interval 1 max-entries这个就是最大的并发连接数量 退出按Q