欢迎来到天天文库
浏览记录
ID:38763647
大小:40.00 KB
页数:43页
时间:2019-06-19
《jsp+js实现可排序表格》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、首先,定义一个js: tableSort.js:functionsort(tableId,sortColumn,nodeType){ vartable=document.getElementById("theTable"); vartableBody=table.tBodies[0]; vartableRows=tableBody.rows; varrowArray=newArray(); for(vari=0;i2、ray[i]=tableRows[i]; } if(table.sortColumn==sortColumn){ rowArray.reverse(); }else{ rowArray.sort(generateCompareTR(sortColumn,nodeType)); } vartbodyFragment=document.createDocumentFragment(); for(vari=0;i3、odyFragment.appendChild(rowArray[i]); } tableBody.appendChild(tbodyFragment); table.sortColumn=sortColumn; } functiongenerateCompareTR(sortColumn,nodeType){ returnfunctioncompareTR(trLeft,trRight){ varleftValue=convert(trLeft.cells[sortColumn].firstC4、hild.nodeValue,nodeType); varrightValue=convert(trRight.cells[sortColumn].firstChild.nodeValue,nodeType); if(leftValuerightValue){ return1; }else{ 5、 return0; } } }; } functionconvert(value,dataType){ switch(dataType){ case"int": returnparseInt(value); case"float": returnparseFloat(value); case"date": returnnewDate(Date.parse(value)); defaul6、t: returnvalue.toString(); } }然后是使用:<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%> <% Stringpath=request.getContextPath(); StringbasePath=request.getScheme()+"://" +request.getServerName()+":"+request.getServerPort() 7、 +path+"/"; %> "> MyJSP'tabel.jsp'startingpage 8、no-cache">
2、ray[i]=tableRows[i]; } if(table.sortColumn==sortColumn){ rowArray.reverse(); }else{ rowArray.sort(generateCompareTR(sortColumn,nodeType)); } vartbodyFragment=document.createDocumentFragment(); for(vari=0;i3、odyFragment.appendChild(rowArray[i]); } tableBody.appendChild(tbodyFragment); table.sortColumn=sortColumn; } functiongenerateCompareTR(sortColumn,nodeType){ returnfunctioncompareTR(trLeft,trRight){ varleftValue=convert(trLeft.cells[sortColumn].firstC4、hild.nodeValue,nodeType); varrightValue=convert(trRight.cells[sortColumn].firstChild.nodeValue,nodeType); if(leftValuerightValue){ return1; }else{ 5、 return0; } } }; } functionconvert(value,dataType){ switch(dataType){ case"int": returnparseInt(value); case"float": returnparseFloat(value); case"date": returnnewDate(Date.parse(value)); defaul6、t: returnvalue.toString(); } }然后是使用:<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%> <% Stringpath=request.getContextPath(); StringbasePath=request.getScheme()+"://" +request.getServerName()+":"+request.getServerPort() 7、 +path+"/"; %> "> MyJSP'tabel.jsp'startingpage 8、no-cache">
3、odyFragment.appendChild(rowArray[i]); } tableBody.appendChild(tbodyFragment); table.sortColumn=sortColumn; } functiongenerateCompareTR(sortColumn,nodeType){ returnfunctioncompareTR(trLeft,trRight){ varleftValue=convert(trLeft.cells[sortColumn].firstC
4、hild.nodeValue,nodeType); varrightValue=convert(trRight.cells[sortColumn].firstChild.nodeValue,nodeType); if(leftValuerightValue){ return1; }else{
5、 return0; } } }; } functionconvert(value,dataType){ switch(dataType){ case"int": returnparseInt(value); case"float": returnparseFloat(value); case"date": returnnewDate(Date.parse(value)); defaul
6、t: returnvalue.toString(); } }然后是使用:<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%> <% Stringpath=request.getContextPath(); StringbasePath=request.getScheme()+"://" +request.getServerName()+":"+request.getServerPort()
7、 +path+"/"; %>
8、no-cache">
此文档下载收益归作者所有