| */ function sortTableInRange(tableId,sortCol,compareType,startRow,endRow,startCol,endCol){ try{ var table = document.getElementById(tableId); // get all row object of the table var objRows = table.getElementsByTagName("tr"); //alert(objRows.length); endRow = (endRow < objRows.length ? endRow : objRows.length); var sortRows = endRow - startRow 1; //alert("sortRows " sortRows); if (sortRows < 2) //only one line,don't sort return ; endCol = (endCol < objRows[1].getElementsByTagName("td").length ? endCol : objRows[1].getElementsByTagName("td").length); // column number of sort //var cols = objRows[1].childNodes.length; var cols = endCol - startCol 1; // define a array to store table cell and sort them var tabData = new BiArray(sortRows,cols); var ari = 0; // retrived table cell data save to array for(i = startRow - 1; i < endRow; i ){ //retrived all <td> cell var cells = objRows[i].getElementsByTagName("td"); var arj = 0; for(var j = startCol - 1; j < endCol; j ){ tabData.setElement(ari,arj,cells.item(j).innerHTML); arj ; } ari ; } if (asce){ if (compareType == "n" || compareType == 'N') tabData.sortLineByNumber(sortCol- startCol); else tabData.sortLine(sortCol - startCol); asce = false; }else{ if (compareType == "n" || compareType == 'N') tabData.sortLineByNumberRev(sortCol - startCol); else tabData.sortLineRev(sortCol - startCol); asce = true; } ari = 0; //update table data with array for(i = startRow -1; i < endRow; i ){ //retrived all <td> cell var cells = objRows[i].getElementsByTagName("td"); arj = 0; for(var j = startCol - 1; j < endCol; j ){ cells.item(j).innerHTML = tabData.getElement(ari,arj); arj ; } ari ; } }catch(e){ alert(e); } } /** 对表格除第一行外的数据行排序,是sortYableInRange(tableId,sortCol,compareType,2,tabRows,1,tabCols) 的特例。 tableId 要排序的表格的id,值格式为 <table id="tb1" > 用于排序的列号,从1开始计数 compareType 排序时比较方式,s-按字符串比较,n-按数值比较 */ function sortTable(tableId,sortCol,compareType){ try{ var table = document.getElementById(tableId); // get all row object of the table var objRows = table.getElementsByTagName("tr"); //alert(objRows.length);
|
| 共6页: 上一页 [1] [2] [3] 4 [5] [6] 下一页 |
评论加载中…