|
1、標題欄、左邊邊欄固定方式更新,取消expression方式;
2、排序方式更新,同時支持數字、字符、日期、數字字符混合、中文漢字的排序;
3、支持換膚,您可以自己定制該控件樣式;
4、預留[雙擊]、[右鍵]功能;
5、支持IE、FF;
CSS:
/*dhdatagrid 大塊樣式*/
#dhdatagrid {position:relative;width:500px;height:200px;background:white;margin:0px;padding:0px;overflow:hidden;border:1px inset;-moz-user-select:none;}
/*dhdatagrid 表格全局樣式*/
#dhdatagrid table {table-layout:fixed;margin:0px;}
#dhdatagrid table td {height:18px;cursor:default;font-size:12px;font-family:verdana;overflow:hidden;white-space:nowrap;text-indent:2px;border-right:1px solid buttonface;border-bottom:1px solid buttonface;}
#dhdatagrid table td .arrow {font-size:8px;color:#808080;}
#dhdatagrid table .lastdata {border-right:none;}
#dhdatagrid table .column {width:120px;cursor:default;background:buttonface;border-top:1px solid #fff;border-right:1px solid #404040;border-bottom:1px solid #404040;border-left:1px solid #fff;}
#dhdatagrid table .over {width:120px;cursor:default;background:buttonface;border-top:1px solid #fff;border-right:1px solid #404040;border-bottom:1px solid #404040;border-left:1px solid #fff;}
#dhdatagrid table .sortdown {width:120px;cursor:default;background:buttonface;border-right:1px solid #ffffff;border-bottom:1px solid #ffffff;border-left:1px solid #404040;border-top:1px solid #404040;position:relative;left:1px;}
#dhdatagrid table .dataover {background:#FAFAFA;}
#dhdatagrid table .firstcolumn {width:30px;text-indent:0px;text-align:center;background:buttonface;border-top:1px solid #fff;border-right:1px solid #404040;border-bottom:1px solid #404040;border-left:1px solid #fff;}
#dhdatagrid table .lastcolumn {background:buttonface;border-top:1px solid #fff;border-right:1px solid #404040;border-bottom:1px solid #404040;border-left:1px solid #fff;}
/*dhdatagrid 選定行樣式*/
#dhdatagrid table .selectedrow {background:highlight;color:white;}
/*dhdatagrid 表頭樣式*/
#dhdatagrid #titlecolumn {width:100%;position:absolute;top:0px;left:0px;z-index:3;}
/*dhdatagrid 左邊欄樣式*/
#dhdatagrid #slidecolumn {width:30px;position:absolute;top:0px;left:0px;z-index:2;}
#dhdatagrid #slidecolumn td {width:30px;text-indent:0px;text-align:center;background:buttonface;border-top:1px solid #fff;border-right:1px solid #404040;border-bottom:1px solid #404040;border-left:1px solid #fff;}
/*dhdatagrid 內容表體樣式*/
#dhdatagrid #datacolumn {width:100%;position:absolute;top:0px;left:0px;}
/*dhdatagrid 原點樣式*/
#dhdatagrid #zero {width:30px;height:18px;margin:0px;padding:0px;position:absolute;top:0px;left:0px;z-index:10;background:buttonface;border-top:1px solid #fff;border-right:1px solid #404040;border-bottom:1px solid #404040;border-left:1px solid #fff;text-align:center;font-size:10px;color:#A19F92;}
JS:
function dhdatagrid(){
//author:dh20156;
this.callname = "dhdg";
this.width = 500;
this.height = 200;
this.rid = "dhdatagrid";
this.columns = [];
this.data = [];
this.dblclick_fun = function(){}
this.contextmenu_fun = function(){}
this.parentNode = document.body;
var dh = this;
var framediv = null;
var zerobj = null;
var leftobj = null;
var titleobj = null;
var dataobj = null;
var hbar = null;
var vbar = null;
var bgbar = null;
//改變列寬初始位置
var ml = 0;
//改變列寬對象初始寬度
var ow = 0;
//改變列寬對象
var tdobj = null;
//當前選定行索引
var nowrow = null;
//是否更改垂直滾動條位置
var changeposv = true;
this.init = function(){
//init the data 初始數據
var dgc = "";
if(this.columns.length>0){
dgc = "<tr><td class=/"firstcolumn/"> </td>";
for(var cc=0;cc<this.columns.length;cc++){
dgc += "<td class=/"column/" onmouseover=/""+this.callname+".over(this);/" onmouseout=/""+this.callname+".out(this);/" onmousemove=/""+this.callname+".cc(event,this);/" onmousedown=/""+this.callname+".rsc_d(event,this);/" onmouseup=/""+this.callname+".mouseup(this);/">"+this.columns[cc]+"<span class=/"arrow/"></span></td>";
}
dgc += "<td class=/"lastcolumn/"> </td></tr>";
}
var dgs = "";
var dgd = "";
if(this.data.length>0){
//第一列
dgs = "<tr><td> </td></tr>";
for(var r=0;r<this.data.length;r++){
dgs += "<tr><td>"+(r+1)+"</td></tr>";
dgd += "<tr onmouseover=/""+this.callname+".dataover(this);/" onmouseout=/""+this.callname+".dataout(this);/"><td class=/"firstcolumn/"> </td>";
for(var c=0;c<this.data[r].length;c++){
dgd += "<td ondblclick=/""+this.callname+".dblclick_fun(this);/" oncontextmenu=/""+this.callname+".contextmenu_fun(this);/">"+this.data[r][c]+"</td>";
}
dgd += "<td class=/"lastdata/"> </td></tr>";
}
if(dgc==""){
dgc = "<tr><td class=/"firstcolumn/"> </td>";
for(var dc=0;dc<this.data[0].length;dc++){
dgc += "<td class=/"column/" onmouseover=/""+this.callname+".over(this);/" onmouseout=/""+this.callname+".out(this);/" onmousemove=/""+this.callname+".cc(event,this);/" onmousedown=/""+this.callname+".rsc_d(event,this);/" onmouseup=/""+this.callname+".mouseup(this);/">Expr"+(dc+1)+"<span class=/"arrow/"></span></td>";
}
dgc += "<td class=/"lastcolumn/"> </td></tr>";
}
}
//dhdatagrid frame 框架
var dgframe = document.createElement("DIV");
dgframe.id = this.rid;
dgframe.onmousedown = function(e){e=e||window.event;getrow(e);}
dgframe.onmousemove = function(e){e=e||window.event;rsc_m(e);}
if(document.attachEvent){
document.attachEvent("onmouseup",rsc_u);
}else{
document.addEventListener("mouseup",rsc_u,false);
}
dgframe.oncontextmenu = function(){return false}
dgframe.onselectstart = function(){return false}
ae(dgframe);
//dhdatagrid zero point 零點
var dgzero = "<div id=/"zero/"></div>"
//dhdatagrid slidecolumn 第一列
var dgslide = "<table cellpadding=/"0/" cellspacing=/"0/" id=/"slidecolumn/">"+dgs+"</table>";
//dhdatagrid column 標題欄
var dgcolumn = "<table cellpadding=/"0/" cellspacing=/"0/" id=/"titlecolumn/">"+dgc+"</table>";
//dhdatagrid data 數據
var dgdata = "<table cellpadding=/"0/" cellspacing=/"0/" id=/"datacolumn/">"+dgc+dgd+"</table>";
//dhdatagrid hbar 水平滾動條
var dghbar = document.createElement("DIV");
dghbar.id = "hbar";
dghbar.style.position = "absolute";
dghbar.style.width = "100%";
dghbar.style.height = "17px";
dghbar.style.top = this.height-17;
dghbar.style.overflowX = "auto";
dghbar.style.zIndex = "10";
dghbar.onscroll = function(){scrh();}
dghbar.innerHTML = "<div style=/"width:100%;height:1px;overflow-y:hidden;/"> </div>";
//dhdatagrid vbar 垂直滾動條
var dgvbar = document.createElement("DIV");
dgvbar.id = "vbar";
dgvbar.style.position = "absolute";
dgvbar.style.width = "17px";
dgvbar.style.height = "100%";
dgvbar.style.left = this.width-17;
dgvbar.style.overflowY = "auto";
dgvbar.style.zIndex = "10";
dgvbar.onscroll = function(){scrv();}
dgvbar.innerHTML = "<div style=/"width:1px;height:100%;overflow-x:hidden;/"> </div>";
//dhdatagrid bgbar 滾動條背景
var dgbgbar = document.createElement("DIV");
dgbgbar.id = "bgbar";
dgbgbar.style.background = "buttonface";
dgbgbar.style.position = "absolute";
dgbgbar.style.width = "100%";
dgbgbar.style.height = "17px";
dgbgbar.style.top = this.height-17;
dgbgbar.style.overflowX = "auto";
dgbgbar.style.zIndex = "9";
dgbgbar.style.display = "none";
dgbgbar.innerHTML = " ";
//appendChild
dgframe.innerHTML = dgzero+dgslide+dgcolumn+dgdata;
dgframe.appendChild(dghbar);
dgframe.appendChild(dgvbar);
dgframe.appendChild(dgbgbar);
this.parentNode.appendChild(dgframe);
if(document.attachEvent){
document.attachEvent("onkeydown",updown);
}else{
document.addEventListener("keydown",updown,false);
}
framediv = dgframe;
zerobj = document.getElementById("zero");
leftobj = document.getElementById("slidecolumn");
titleobj = document.getElementById("titlecolumn");
dataobj = document.getElementById("datacolumn");
hbar = dghbar;
vbar = dgvbar;
bgbar = dgbgbar;
var btt = getCurrentStyle(framediv,"borderTopWidth");
var btr = getCurrentStyle(framediv,"borderRightWidth");
var btb = getCurrentStyle(framediv,"borderBottomWidth");
var btl = getCurrentStyle(framediv,"borderLeftWidth");
var fh = getCurrentStyle(framediv,"height");
var zh = getCurrentStyle(zerobj,"height");
var zbt = getCurrentStyle(zerobj,"borderTopWidth");
var zbb = getCurrentStyle(zerobj,"borderBottomWidth");
if(document.all){
vbar.style.left = parseInt(vbar.style.left)-parseInt(btr)-parseInt(btl);
}else{
framediv.style.height = parseInt(fh)-parseInt(btb)-parseInt(btt);
zerobj.style.height = parseInt(zh)-parseInt(zbb)-parseInt(zbt);
}
hbar.style.top = parseInt(hbar.style.top)-parseInt(btb)-parseInt(btt);
bgbar.style.top = parseInt(bgbar.style.top)-parseInt(btb)-parseInt(btt);
}
function getCurrentStyle(oElement, sProperty) {
if(oElement.currentStyle){
return oElement.currentStyle[sProperty];
}else if(window.getComputedStyle){
sProperty = sProperty.replace(/([A-Z])/g, "-$1").toLowerCase();
return window.getComputedStyle(oElement, null).getPropertyValue(sProperty);
}else{
return null;
}
}
//設置塊滾動條
this.setwh = function(){
hbar.style.display = "block";
vbar.style.display = "block";
hbar.childNodes[0].style.width = dataobj.offsetWidth;
vbar.childNodes[0].style.height = dataobj.offsetHeight;
if(hbar.childNodes[0].offsetWidth<=hbar.offsetWidth){
hbar.style.display = "none";
}else{
hbar.style.display = "block";
}
if(vbar.childNodes[0].offsetHeight<=vbar.offsetHeight){
vbar.style.display = "none";
}else{
vbar.style.display = "block";
}
if(hbar.childNodes[0].offsetWidth>hbar.offsetWidth && vbar.childNodes[0].offsetHeight>vbar.offsetHeight && changeposv){
bgbar.style.display = "block";
hbar.style.width = hbar.offsetWidth-17;
vbar.style.height = vbar.offsetHeight-17;
vbar.childNodes[0].style.height = vbar.childNodes[0].offsetHeight+17;
changeposv = false;
}
if(hbar.childNodes[0].offsetWidth<=hbar.offsetWidth+17 && !changeposv){
bgbar.style.display = "none";
hbar.childNodes[0].style.width = 0;
hbar.style.width = hbar.offsetWidth+17;
vbar.style.height = vbar.offsetHeight+17;
changeposv = true;
if(vbar.offsetHeight-dataobj.offsetHeight>dataobj.offsetTop && document.all){
leftobj.style.top = leftobj.offsetTop+17;
dataobj.style.top = dataobj.offsetTop+17;
}
}
}
//鼠標滾輪,列表滾動事件
function mwEvent(e){
e=e||window.event;
if(e.wheelDelta<=0 || e.detail>0){
vbar.scrollTop += 18;
}else {
vbar.scrollTop -= 18;
}
}
function ae(obj){
if(document.attachEvent){
obj.attachEvent("onmousewheel",mwEvent);
}else{
obj.addEventListener("DOMMouseScroll",mwEvent,false);
}
}
//滾動條事件
function scrv(){
leftobj.style.top = -(vbar.scrollTop);
dataobj.style.top = -(vbar.scrollTop);
}
function scrh(){
titleobj.style.left = -(hbar.scrollLeft);
dataobj.style.left = -(hbar.scrollLeft);
}
//選擇行
function getrow(e){
e=e||window.event;
var esrcobj = e.srcElement?e.srcElement:e.target;
if(esrcobj.parentNode.tagName=="TR"){
var epobj = esrcobj.parentNode;
var eprowindex = epobj.rowIndex;
if(eprowindex!=0){
if(nowrow!=null){
dataobj.rows[nowrow].className = "";
}
dataobj.rows[eprowindex].className = "selectedrow";
nowrow = eprowindex;
}
}
}
//更改列寬
this.rsc_d = function(e,obj){
var px = document.all?e.offsetX:e.layerX-obj.offsetLeft;
if(px>obj.offsetWidth-6 && px<obj.offsetWidth){
e=e||window.event;
obj=obj||this;
ml = e.clientX;
ow = obj.offsetWidth;
tdobj = obj;
if(obj.setCapture){
obj.setCapture();
}else{
e.preventDefault();
}
}else{
if(nowrow!=null){
dataobj.rows[nowrow].className = "";
}
if(obj.getAttribute("sort")==null){
obj.setAttribute("sort",0);
}
var sort = obj.getAttribute("sort");
if(sort==1){
dgsort(obj,true);
obj.setAttribute("sort",0);
}else{
dgsort(obj,false);
obj.setAttribute("sort",1);
}
obj.className = "sortdown";
}
}
this.mouseup = function(obj){
obj.className = "over";
}
function rsc_m(e){
if(tdobj!=null){
e=e||window.event;
var newwidth = ow-(ml-e.clientX);
if(newwidth>5){
tdobj.style.width = newwidth;
dataobj.rows[0].cells[tdobj.cellIndex].style.width = newwidth;
}else{
tdobj.style.width = 5;
dataobj.rows[0].cells[tdobj.cellIndex].style.width = 5;
}
dh.setwh();
scrh();
}
}
function rsc_u(e){
if(tdobj!=null){
e=e||window.event;
var newwidth = ow-(ml-e.clientX);
if(newwidth>5){
tdobj.style.width = newwidth;
dataobj.rows[0].cells[tdobj.cellIndex].style.width = newwidth;
}else{
tdobj.style.width = 5;
dataobj.rows[0].cells[tdobj.cellIndex].style.width = 5;
}
if(tdobj.releaseCapture){
tdobj.releaseCapture();
}
ml = 0;
ow = 0;
tdobj = null;
}
dh.setwh();
scrh();
}
this.cc = function(e,obj){
var px = document.all?e.offsetX:e.layerX-obj.offsetLeft;
if(px>obj.offsetWidth-6 && px<obj.offsetWidth){
obj.style.cursor = "col-resize";
}else{
obj.style.cursor = "default";
}
}
this.over = function(obj){
obj.className = "over";
}
this.out = function(obj){
obj.className = "column";
}
this.dataover = function(obj){
if(obj.rowIndex!=nowrow){
obj.className = "dataover";
}
}
this.dataout = function(obj){
if(obj.rowIndex!=nowrow){
obj.className = "";
}
}
//鍵盤Up & Down事件
function updown(e){
e=e || window.event; e=e.which || e.keyCode;
var rl = dh.data.length;
switch(e){
case 38://Up;
if(nowrow!=null && nowrow>1){
vbar.scrollTop -= 18;
dataobj.rows[nowrow].className = "";
nowrow -= 1;
dataobj.rows[nowrow].className = "selectedrow";
};
break;
case 40://Down;
if(nowrow!=null && nowrow<rl){
vbar.scrollTop += 18;
dataobj.rows[nowrow].className = "";
nowrow += 1;
dataobj.rows[nowrow].className = "selectedrow";
};
break;
default:break;
}
}
function dti(s){
var n = 0;
var a = s.match(//d+/g);
for(var i=0;i<a.length;i++){
if(a[i].length<2){
a[i] = "0"+a[i];
}
}
n = a.join("");
return n;
}
//排序
function dgsort(obj,asc){
var rl = dh.data.length;
var ci = obj.cellIndex;
var rowsobj = [];
for(var i=1;i<dataobj.childNodes[0].rows.length;i++){
rowsobj[i-1] = dataobj.childNodes[0].rows[i];
}
rowsobj.sort(function(trObj1,trObj2){
if(!isNaN(trObj1.cells[ci].innerHTML.charAt(0)) && !isNaN(trObj2.cells[ci].innerHTML.charAt(0))){
if(asc){
return dti(trObj1.cells[ci].innerHTML)-dti(trObj2.cells[ci].innerHTML);
}else{
return dti(trObj2.cells[ci].innerHTML)-dti(trObj1.cells[ci].innerHTML);
}
}else{
if(asc){
return trObj1.cells[ci].innerHTML.localeCompare(trObj2.cells[ci].innerHTML);
}else{
return trObj2.cells[ci].innerHTML.localeCompare(trObj1.cells[ci].innerHTML);
}
}
});
for(var i=0;i<rowsobj.length;i++){
dataobj.childNodes[0].appendChild(rowsobj[i]);
}
for(var c=1;c<obj.parentNode.cells.length-1;c++){
obj.parentNode.cells[c].childNodes[1].innerHTML = "";
}
if(asc){
obj.childNodes[1].innerHTML = "▲";
}else{
obj.childNodes[1].innerHTML = " 主站蜘蛛池模板: 在线国产片 | 最新国产毛片 | 日韩视频 中文字幕 | 99pao在线视频成精品 | 亚洲欧美色一区二区三区 | 日本欧美一区二区三区不卡视频 | 手机在线成人精品视频网 | 国产精品自在自线 | 在线观看91精品国产不卡免费 | 色综合一区二区三区 | 日本精品一区二区三区视频 | 97青草香蕉依人在线播放 | 91tm视频| 日本老年人精品久久中文字幕 | 激情五月婷婷在线 | 日韩久久网| 国产小视频免费在线观看 | 国产精品嫩草影视在线观看 | 亚洲资源在线 | 在线观看色网 | a加勒比一本东京 | 91精彩视频在线观看 | 亚洲性久久 | 55夜色66夜色国产精品站 | 亚洲欧洲国产经精品香蕉网 | 亚洲欧美国产精品 | 91麻豆免费观看 | 国产精品福利午夜一级毛片 | 快播黄色 | 四虎影视免费永久在线观看 | 伊人久久大香线焦在观看 | 婷婷色基地 | 激情综合五月婷婷 | 日韩精品一区二区三区中文在线 | 日日久 | 99热这里有免费国内精品 | 成人夜色视频在线观看网站 | 99成人精品 | 99在线免费播放 | 91亚洲精品视频 | 国产乱码精品一区二区三区中 |