table排序类
.fu_list{ width:400px; border:1px solid #ebebeb;line-height:20px; font-size:12px;}
.fu_list thead td{background-color:#ebebeb;}
.fu_list td{padding:5px;}
.fu_list a{outline:none;/*ff*/hide-focus:expression(this.hidefocus=true);/*ie*/ text-decoration:none; color:#333;}
.fu_list thead a{padding-right:15px;}
.fu_list thead a.up, .fu_list thead a.down{ background:url(up.gif) right center no-repeat; }
.fu_list thead a.down{background-image:url(down.gif);}
var $ = function (id) {
return "string" == typeof id ? document.getelementbyid(id) : id;
};
var class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
function each(list, fun){
for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};
/////////////////////////////////////
////////////////////////////////
var tableorder = class.create();
tableorder.prototype = {
initialize: function(tbody) {
var othis = this;
this.body = $(tbody);//tbody对象
this.rows = [];//行集合
each(this.body.rows, function(o){ othis.rows.push(o); })
},
//排序并显示
sort: function(order) {
//排序
this.rows.sort(this.compare(order));
order.down && this.rows.reverse();
//显示表格
var ofragment = document.createdocumentfragment();
each(this.rows, function(o){ ofragment.appendchild(o); });
this.body.appendchild(ofragment);
},
//比较函数
compare: function(order) {
var othis = this;
return function(o1, o2) {
var value1 = othis.getvalue(o1, order), value2 = othis.getvalue(o2, order);
return value1 < value2 ? -1 : value1 > value2 ? 1 : 0;
};
},
//获取比较值
getvalue: function(tr, order) {
var data = tr.getelementsbytagname("td")[order.index].getattribute(order.attribute);
//数据转换
switch (order.datatype.tolowercase()) {
case "int":
return parseint(data) || 0;
case "float":
return parsefloat(data) || 0;
case "date":
return date.parse(data) || 0;
case "string":
default:
return data.tostring() || "";
}
},
//添加并返回一个排序对象
add: function(index, options) {
var othis = this;
return new function(){
//默认属性
this.attribute = "innerhtml";//获取数据的属性
this.datatype = "string";//数据类型
this.down = false;//是否按顺序
object.extend(this, options || {});
//排序对象的属性
this.index = index;
this.sort = function(){ othis.sort(this); };
};
}
}
var to = new tableorder("idlist");
function setorder(obj, index, options){
var o = $(obj);
//添加一个排序对象
var order = to.add(index, options);
o.onclick = function(){
//取相反排序
order.down = !order.down;
//设置样式
each(setorder._arr, function(o){ o.classname = ""; })
o.classname = order.down ? "down" : "up";
//排序显示
order.sort();
return false;
}
//_arr是记录排序项目(这里主要用来设置样式)
setorder._arr ? setorder._arr.push(o) : setorder._arr = [];
}
setorder("idtitle", 0);
setorder("idext", 0, { attribute: "_ext" });
setorder("idaddtime", 1, { attribute: "_order", datatype: "date" });
setorder("idsize", 2, { attribute: "_order", datatype: "int" });
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]
| 名称 / 类型 | 上传时间 | 大小 |
| new.rar | 2008-9-12 8:51:09 | 423.09 k |
| tagcontrol.js | 2008-9-23 11:26:57 | 1.35 k |
| scroller.js | 2008-9-23 11:26:57 | 2.5 k |
| alertbox.js | 2008-9-23 11:26:57 | 3.48 k |
| 1.htm | 2008-10-4 20:21:54 | 11.13 k |
| 4.htm | 2008-10-4 20:21:54 | 351 b |
| news.xml | 2008-10-4 20:24:11 | 13.74 k |
| news.xsl | 2008-10-4 20:24:11 | 16.4 k |
| function.js | 2008-10-4 20:24:11 | 2.78 k |
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!