javascript表格控件:Chgrid,简化型

本着自由共享的精神,把代码帖出来,同时大家也可以一起来测试以及添加新功能,请大家根据网友提出的问题,把自己修改好的版本都帖出来跟在下面,最后作为一款比较全面的表格软件。
Chgrid的简单功能介绍:
1:支持自定义排序
2:支持列宽度的拖放
3:支持自定义函数
4:支持分页
5:支持自动编号
6:多浏览器支持,支持ie6,ie7,ff,opera
7:div布局

已知问题:
1:由于使用的div布局,如果使用margin或者padding会改变定义的列宽度,所以目前文字只能居中或者靠左或靠右,不能使用padding控制位置
目前解决办法是可以在每个div里面再附加一个div,用这个div的margin属性来控制其位置。
2:内容在超出容器宽度的时候,拖动会有点小问题,。

怎样修改样式:
如果不改变风格,大家只要对如下部分代码调整就可以
Chgrid_column0{ width:20px;}
.Chgrid_column1{ width:100px;}
.Chgrid_column2{ width:80px;}
.Chgrid_column3{ width:120px;}
.Chgrid_column4{ width:100px;}
每多一列就再加一行比如.Chgrid_column5{ width:100px;}
注意:最后一列是不用定义宽度的,程序会自动调整

无标题文档

#Chgrid_container{ font:12px "宋体"; width:600px; height:100%; color:#827200;}
.Chgrid_head_row{ width:100%; border-top:1px solid #ffb517; border-bottom:1px solid #ffb517; background-color:#ffe6b3
; height:20px;}
.Chgrid_row{ width:100%; border-bottom:1px solid #ffb517; height:20px; background-color:#fff}
.Chgrid_row_interval{width:100%; border-bottom:1px solid #ffb517; height:20px; background-color:#fff2d9}
.Chgrid_row_hilight{width:100%; border-bottom:1px solid #ffb517; height:20px; background-color:#ffe6b3}
.Chgrid_column{ float:left; height:20px; overflow:hidden; line-height:20px; text-align: center;}
.Chgrid_column_sort_desc{ float:left; height:20px; overflow:hidden; line-height:20px; text-align: center;background-image:url(http://bbs.blueidea.com/attachments/2007/3/15/20070315_2402590937239704896fuxTNS4SQ9xDC.gif); background-position:right center;background-repeat:no-repeat;}
.Chgrid_column_sort_asc{ float:left; height:20px; overflow:hidden; line-height:20px; text-align: center;background-image:url(http://bbs.blueidea.com/attachments/2007/3/15/20070315_6f504cdc131612d66f08J1jtbM8fwxHJ.gif); background-position:right center;background-repeat:no-repeat;}
.Chgrid_head_split{float:left; height:20px; width:2px; background-image:url(http://bbs.blueidea.com/attachments/2007/3/15/20070315_2aedec010331a8ccc38caDdGOQhsA048.gif); background-position:center;background-repeat:no-repeat; cursor: e-resize; cursor: col-resize; }
.Chgrid_table_cell0{ float:left; height:20px; line-height:20px; overflow:hidden; text-align: center;}
.Chgrid_table_cell{ float:left; height:20px; line-height:20px; overflow:hidden; text-align: center; border-left:1px solid #ffb517;}

.Chgrid_column0{ width:20px;}
.Chgrid_column1{ width:100px;}
.Chgrid_column2{ width:80px;}
.Chgrid_column3{ width:120px;}
.Chgrid_column4{ width:100px;}

.button{ font:12px "宋体"; color:#827200; padding-left:12px; padding-right:12px; background-color:#ffe6b3; border-left:2px solid #fff;border-top:2px solid #fff;border-right:2px solid #ffb517;border-bottom:2px solid #ffb517;}

var Chgrid = {
dragobj : null,
cloneobj : null,
init : function(id,ps,minirows,show,inter,hili,sortby,columnArr,dataArr,sortable){
this.container = $(id); //容器对象,字符串
this.pageSize = ps; //分页大小,整数
this.minirows = minirows; //最少行数,整数
this.rowInterval = inter; //是否隔行,boolean值
this.hilight = hili; //是否高亮,boolean值
this.showAutoGridNum = show; //是否显示自动编号,boolean值
this.sortBy = sortby; //排序规则,0表示降序或1表示升序
this.column = columnArr; //栏目,数组
this.data = dataArr; //数据,数组
this.selectedRowIndex = 0; //当前选中行的索引,整数
this.startPage = 0; //当前分页号,整数
Chgrid.setSortAble(sortable); //确定哪些列可以排序,数组
Chgrid.drawGrid();
document.onmousemove = Chgrid.drag;
document.onmouseup = Chgrid.end;
},
setSortAble : function(){
this.sortColumn = [];
if(sortable){
this.sortColumn = sortable;
}else{
this.sortColumn[0] = false;
for(var i=0;i objNextOffsetLeft + Chgrid.cloneobj.nextSibling.offsetWidth - 2){
Chgrid.finalMouseX = objNextOffsetLeft + Chgrid.cloneobj.nextSibling.offsetWidth - 2;
}
Chgrid.dragobj.style.left = Chgrid.finalMouseX + "px";
},
end : function(e) {
if(Chgrid.cloneobj==null)return;
var obj = Chgrid.cloneobj;
obj.previousSibling.style.width = obj.previousSibling.offsetWidth + (Chgrid.finalMouseX - Chgrid.initMouseX) + "px";
obj.nextSibling.style.width = obj.nextSibling.offsetWidth - (Chgrid.finalMouseX - Chgrid.initMouseX) + "px";
Chgrid.resizeWidth(obj);
Chgrid.cloneobj = null;
Chgrid.dragobj.parentNode.removeChild(Chgrid.dragobj);
},
resizeWidth : function(obj){
var j = this.getObjectIndex(this.header,obj);
for(var i=1;ib[col] ? 1:(a[col]b[col] ? -1:0)));});
Chgrid.fillData(Chgrid.startPage);
if(Chgrid.sortBy==0)
this.className = this.className.replace(/Chgrid_column /,"Chgrid_column_sort_asc ");
else
this.className = this.className.replace(/Chgrid_column /,"Chgrid_column_sort_desc ");
Chgrid.sortBy = (Chgrid.sortBy == 0 ? 1 : 0);
};
}
}
if(totalWidth>this.header.offsetWidth){
this.header.style.width = totalWidth + "px";
}else{
if(totalWidth parseInt(pageNum))pageNum=parseInt(pageNum)+1;
if(startPagepageNum)return;
this.startPage = startPage;
Chgrid.removeData();
var endNum = startPage * this.pageSize;
if(endNum > this.data.length) endNum = this.data.length;
var oRow = this.container.childNodes[1];
for(var i=(startPage-1)*this.pageSize;i0){
Chgrid.container.childNodes[k].className = Chgrid.container.childNodes[k].oldClass;
}
this.className = "Chgrid_row_hilight";
}

var j= Chgrid.getObjectIndex(Chgrid.container,this);
Chgrid.selectedRowIndex = j;
},
getObjectIndex : function(parent,obj){
var j = 0;
for(var i=0;i Chgrid.startPage*Chgrid.pageSize || !data[i])return;
var promp = prompt("请输入新的值","");
if(promp!=null){

var j = Chgrid.getObjectIndex(obj.parentNode,obj);
obj.innerHTML = promp;
Chgrid.updateData(i,j,promp);
}
//obj.editStatus = true;
//}
}

function $(id){
return document.getElementById(id);
}

var column = ["编号","姓名","性别","职位","电话","住址"];
var sortable = [false,true,true,true]
var data = [["","cityvoice","帅哥","Javascript Programmer","13300000000","康定路112弄4号"],["","melody","美女","UI Programmer","13400000000","南京西路112弄4号"],["","jeson","帅哥","Board","13500000000","北京路112弄4号"],["","yanguo","帅哥","Project Manager","13600000000","武定路112弄4号"],["","duanyu","帅哥","C# Programmer","13700000000","河南南路112弄4号"],["","xiaolonglv","美女","ASP Programmer","13800000000","陕西北路112弄4号"],["","rose","美女","Java Programmer","13900000000","西康路112弄4号"],["","cityvoice","帅哥","Javascript Programmer","13300000000","康定路112弄4号"],["","melody","美女","UI Programmer","13400000000","南京西路112弄4号"],["","jeson","帅哥","Board","13500000000","北京路112弄4号"],["","yanguo","帅哥","Project Manager","13600000000","武定路112弄4号"],["","duanyu","帅哥","C# Programmer","13700000000","河南南路112弄4号"],["","xiaolonglv","美女","ASP Programmer","13800000000","陕西北路112弄4号"],["","rose","美女","Java Programmer","13900000000","西康路112弄4号"],["","cityvoice","帅哥","Javascript Programmer","13300000000","康定路112弄4号"],["","melody","美女","UI Programmer","13400000000","南京西路112弄4号"],["","jeson","帅哥","Board","13500000000","北京路112弄4号"],["","yanguo","帅哥","Project Manager","13600000000","武定路112弄4号"],["","duanyu","帅哥","C# Programmer","13700000000","河南南路112弄4号"],["","xiaolonglv","美女","ASP Programmer","13800000000","陕西北路112弄4号"],["","rose","美女","Java Programmer","13900000000","西康路112弄4号"],["","cityvoice","帅哥","Javascript Programmer","13300000000","康定路112弄4号"],["","melody","美女","UI Programmer","13400000000","南京西路112弄4号"],["","jeson","帅哥","Board","13500000000","北京路112弄4号"],["","yanguo","帅哥","Project Manager","13600000000","武定路112弄4号"],["","duanyu","帅哥","C# Programmer","13700000000","河南南路112弄4号"],["","xiaolonglv","美女","ASP Programmer","13800000000","陕西北路112弄4号"],["","rose","美女","Java Programmer","13900000000","西康路112弄4号"],["","cityvoice","帅哥","Javascript Programmer","13300000000","康定路112弄4号"],["","melody","美女","UI Programmer","13400000000","南京西路112弄4号"],["","jeson","帅哥","Board","13500000000","北京路112弄4号"],["","yanguo","帅哥","Project Manager","13600000000","武定路112弄4号"],["","duanyu","帅哥","C# Programmer","13700000000","河南南路112弄4号"],["","xiaolonglv","美女","ASP Programmer","13800000000","陕西北路112弄4号"],["","rose","美女","Java Programmer","13900000000","西康路112弄4号"],["","cityvoice","帅哥","Javascript Programmer","13300000000","康定路112弄4号"],["","melody","美女","UI Programmer","13400000000","南京西路112弄4号"],["","jeson","帅哥","Board","13500000000","北京路112弄4号"],["","yanguo","帅哥","Project Manager","13600000000","武定路112弄4号"],["","duanyu","帅哥","C# Programmer","13700000000","河南南路112弄4号"],["","xiaolonglv","美女","ASP Programmer","13800000000","陕西北路112弄4号"],["","rose","美女","Java Programmer","13900000000","西康路112弄4号"],["","cityvoice","帅哥","Javascript Programmer","13300000000","康定路112弄4号"],["","melody","美女","UI Programmer","13400000000","南京西路112弄4号"],["","jeson","帅哥","Board","13500000000","北京路112弄4号"],["","yanguo","帅哥","Project Manager","13600000000","武定路112弄4号"]]

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

其它优秀的grid控件参考:
http://www.activewidgets.com
http://www.yui-ext.com/deploy/ext-1.0-alpha3/docs/

请千万不要把我这款控件跟它们比较,差距较大,不过我也有优势,使用起来比较简单,速度也快:)
本来想多加点数据,结果发现超过限制了,大家测试的时候自己多搞点数据测试其速度如何。

[ 本帖最后由 cityvoice 于 2007-3-15 16:52 编辑 ]

(0)

相关推荐

  • jquery miniui 教程 表格控件 合并单元格应用

    表格:合并单元格 参考示例:合并单元格 调用方法:margeCells.如下代码: 复制代码 代码如下: grid.on("load", onLoad); function onLoad(e) { var grid = e.sender; var marges = [ { rowIndex: 1, columnIndex: 0, rowSpan: 1, colSpan: 2 }, { rowIndex: 3, columnIndex: 0, rowSpan: 4, colSpan: 3

  • JQuery FlexiGrid的asp.net完美解决方案 dotNetFlexGrid-.Net原生的异步表格控件

    dotNetFlexGrid是一款asp.net原生的异步表格控件,他的前身是Jquery FlexiGrid插件,我们重构了FlexiGrid的大部分Javascript代码,使其工作的更有效率,BUG更少:同时将其封装为dotNet控件,提供了简单易用的使用方式. dotNetFlexGrid扩展和优化了FlexiGrid原有的功能,并提供了更多具有针对性的功能,使用dotNetFlexGrid,您的用户可以轻松拥有如下功能 提供简易的方式自行调整表格列宽 根据实际情况调整表格的大小 针对合

  • ASP.NET Table 表格控件的使用方法

    一个Table对象包含多个行TableRow,每一行又包含TableCell,TableCell中可以包含其他的HTML或者服务器控件作为Web服务器控件. 一.Table中的属性 Table对象: BackImageUrl 表格的背景图像的URL Caption 表格标题 CaptionAlign 标题文本对齐方式 CellPadding Table单元格内容和单元格边框之间的空间量(单位:像素) CellSpacing 相邻单元格之间的空间量 Rows Table控件中行的集合 TableR

  • 详解能在多种前端框架下使用的表格控件

    近几年Web前端框架特别流行,比如AngularJS.AngularJS 2.ReactJS.KnockoutJS.VueJS等.表格控件是我们在开发中经常要用到的控件.有没有能够在多种前端控件下都能使用的表格控件?最近研究发现Wijmo中的FlexGrid是一款不错的表格控件,它能支持很多主流的框架.这里主要介绍在纯JavaScript和AngularJS下FlexGrid的使用. 一.在纯JavaScript下使用FlexGrid HTML文件: <!DOCTYPE html> <h

  • ExtJS 配置和表格控件使用第1/2页

    ExtJS是一套完整的RIA解决方案,也因为功能完整造成了ext-all.js有400多k,由于是基于JS和CSS的功能实现,对客户端机器性能也有一定的要求,即不支持IE6以下的版本.如果您的项目对网页响应时间有严格的限制,或者客户端操作系统过于陈旧,一定不要选择ExtJS. 本文主要是介绍ExtJS的下载和配置以及一些简单的使用方法.目前最新版本为3.0,但是本文主要介绍2.2版本. 一.ExtJS下载以及配置 1.下载地址:www.extjs.com/(这是官网,大家可以选择自己喜欢的版本下

  • 最棒的Angular2表格控件

    现在市面上有大量的JavaScript数据表格控件,包括开源的第三方的和自产自销的.可以说Wijmo的Flexgrid是目前适应Angular 2的最好的表格控件. Angular 2数据表格基本要求: 更小.更快.更熟悉. 为了使用Angular 2表格,首先你需要了解表格的基本要求.FlexGrid开始于1996年,当时使用C++为Visual Basic编写的控件.多年来,它不断进化并在多个平台得到完善,尤其是JavaScript平台.FlexGrid 因为Flex的理念而命名,控件应当包

  • Android自定义表格控件满足人们对视觉的需求

    Android平台已经给我们提供了很多标准的组件,如:TextView.EditView.Button.ImageView.Menu等,还有许多布局控件,常见的有:AbsoluteLayout.LinerLayout.RelativeLayout.TableLayout等.但随着人们对视觉的需求,基本组件已无法满足人们求新求异的要求,于是我们常常会自定义组件,用来实现更美观的UI界面. 实现自定义控件通常有两种途径,一种是继承View类,重写其中的重要方法,另一种是继承ViewGroup类,通过

  • 左侧是表头的JS表格控件(自写,网上没有的)

    今天,项目中要用到该表格,找了一遍,发现没有合适的,于是自己动手丰衣足食.  最终呈现效果如上图, 1.左侧是表头的表格数据展现, 2.支持多行,多表头 3.固定表头的功能 4.能够支持标题 5.获取表格中的数据 6.支持IE/CHROME 7. 表格能够自适应根据内容行居中 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xh

  • Android自定义DataGridView数据表格控件

    我是一个.net程序员,但是苦于公司要求开发一个android app,没办法,只能硬着头皮上了. 由于项目里面很多地方需要用到数据显示控件(类似于.net的DataGridView),度娘找了下发现没人公开类似的控件,没办法只好自己写了. 废话不多说,直接贴代码: public class DataGridView extends HorizontalScrollView { private List<DataGridViewColumn> columns; private List<

  • 在web中js实现类似excel的表格控件

    Execl功能非常强大,内置的很多函数或公式可以大大提高对数据的加工处理能力.那么在web中有没有类似的控件呢?经过一番搜寻,发现handsontable具备了基本的excel功能支持公式,同时能对数据进行实时编辑.另外支持拖动复制.Ctrl+C .Ctrl+V 等等.在浏览器支持方面,它支持以下的浏览器: IE7+, FF, Chrome, Safari, Opera. 首先引入相关库文件,公式支持不包含在handsontable.full.js中,需要单独引入: <script src=&quo

随机推荐