DataGrid点击标题进行排序的JS
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0026)http://aspx.cc/aspx.cc.htm -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><PUBLIC:ATTACH
ONEVENT="cleanup()" EVENT="ondetach"></PUBLIC:ATTACH>
<SCRIPT language=javascript>
var TableName = "AspxCC";
var ParentObj = null;
function ClickThis(e)
{
if(ParentObj != null)
{
ParentObj.style.backgroundColor = "#FFFFFF";
}
e.style.backgroundColor = "#DEF8FF";
ParentObj = e;
e.style.backgroundColor = "#DEF8FF";
}
function window.onload()
{
var Obj = eval("document.all."+ TableName +".rows;");
for(var i=1; i<Obj.length; i++)
{
Obj[i].onclick = new Function("ClickThis(this)");
}
var ObjHead = eval("document.all."+ TableName +".rows[0].cells");
for(var i=0; i<ObjHead.length; i++)
{
ObjHead[i].innerHTML = "<span style=\"cursor:hand;width:100%\" onclick=\"Order(this)\">"+ ObjHead[i].innerHTML +"</span>";
}
}
var ParentNode = null;
function Order(e)
{
if(ParentNode != null && ParentNode != e)
{
ParentNode.innerText = ParentNode.innerText.replace(UP(),'').replace(Down(),'');
}
if(ParentNode != e)
{
e.innerText = e.innerText.replace(UP(),'').replace(Down(),'') + UP();
OrderThis(e,"D");
}
else
{
if(e.innerText.replace(UP(),'') != e.innerText)
{
e.innerText = e.innerText.replace(UP(),'').replace(Down(),'') + Down();
OrderThis(e,"U");
}
else
{
e.innerText = e.innerText.replace(UP(),'').replace(Down(),'') + UP();
OrderThis(e,"D");
}
}
ParentNode = e;
}
function UP()
{
return "▼";
}
function Down()
{
return "▲";
}
function OrderThis(e, Order)
{
var Rows;
var ObjHead = eval("document.all."+ TableName +".rows[0].cells");
for(var i=0; i<ObjHead.length; i++)
{
if(ObjHead[i].childNodes[0] == e)
{
Rows = i;
break;
}
}
//alert(Rows);
//alert(Order);
var Obj = eval("document.all."+ TableName);
var d = new Date();
ShordOrder(Obj, Rows, Order);
alert("时间:"+ (new Date()-d) +" 行数:"+ Obj.rows.length);
}
//
// objTB 表名 index所选择的列 Order选择的排序方式(D,U)
// 关键方法 排序
//
function ShordOrder(objTB,index, Order){
var i;
var j;
for(i=1;i<(objTB.rows.length-1);i++){
for(j=i+1;j<objTB.rows.length;j++)
{
if(Order == "D")
{
if(objTB.rows[j].cells[index].innerText.valueOf() > objTB.rows[i].cells[index].innerText.valueOf())
{
objTB.moveRow(j,i);
}
}
else
{
if(objTB.rows[j].cells[index].innerText.valueOf() < objTB.rows[i].cells[index].innerText.valueOf())
{
objTB.moveRow(j,i);
}
}
}
}
}
</SCRIPT>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY>
<TABLE id=AspxCC style="FONT-SIZE: 12px" cellSpacing=0 borderColorDark=#ffffff
cellPadding=2 width="100%" borderColorLight=#888888 border=1>
<TBODY>
<TR align=center bgColor=#dcdcdc>
<TD>用户编号</TD>
<TD>试用时间</TD>
<TD>转正时间</TD>
<TD>性别</TD>
<TD>姓名拼音</TD>
<TD>生日时间</TD>
<TD>民族</TD>
<TD>身高</TD></TR>
<TR>
<TD>2000001</TD>
<TD>1997-3-13 0:00:00</TD>
<TD>1997-3-13 0:00:00</TD>
<TD>1</TD>
<TD>WZJ</TD>
<TD>1965-3-13 0:00:00</TD>
<TD>汉</TD>
<TD>171</TD></TR>
<TR>
<TD>2000045</TD>
<TD>2001-2-15 0:00:00</TD>
<TD>2001-3-15 0:00:00</TD>
<TD>0</TD>
<TD>WY</TD>
<TD>1978-8-5 0:00:00</TD>
<TD>汉</TD>
<TD>162</TD></TR>
<TR>
<TD>2000046</TD>
<TD>2001-2-23 0:00:00</TD>
<TD>2001-3-23 0:00:00</TD>
<TD>0</TD>
<TD>LQ</TD>
<TD>2001-2-23 0:00:00</TD>
<TD>汉</TD>
<TD>171</TD></TR>
</TBODY></TABLE></BODY></HTML>
本文来自: 站长(http://www.qqcf.com/) 详细出处参考:http://study.qqcf.com/web/716/224820.htm