Develop and Download Open Source Software

Browse Subversion Repository

Contents of /js/order_by_column.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations) (download) (as text)
Fri Dec 4 12:17:36 2009 UTC (14 years, 5 months ago) by berupon
File MIME type: application/x-javascript
File size: 2487 byte(s)
まだ完成していないけど途中経過の記録というか…backupとしてcommit
1 var OrderByColumn=Class.create();
2
3 OrderByColumn.prototype={
4 initialize: function(table,type){
5 if(typeof table == "string"){
6 table=document.getElementById(table);
7 };
8 this.type=type;
9 this.table=table;
10 this.th=$A(this.table.getElementsByTagName("thead")[0].getElementsByTagName("th"));
11 this.td=$A(this.table.getElementsByTagName("tbody")[0].getElementsByTagName("td"));
12 this.tr=$A(this.table.getElementsByTagName("tbody")[0].getElementsByTagName("tr"));
13
14 this.th.each(function(v){
15 v.style.cursor="pointer";
16 var sp=document.createElement("span");
17 sp.className="OBRarrow";
18 v.appendChild(sp);
19
20 Event.observe(v,"click",function(){
21 this.sort(v);
22 }.bind(this));
23 }.bind(this));
24 }
25
26
27 ,marking: function(th){
28 var current=th.lastChild.innerHTML;
29 this.th.each(function(v){
30 v.lastChild.innerHTML="";
31 });
32 switch(current){
33 case "":
34 th.lastChild.innerHTML="▲";
35 return "asc";
36 break;
37
38 case "▲":
39 th.lastChild.innerHTML="▼";
40 return "desc";
41 break;
42
43 case "▼":
44 th.lastChild.innerHTML="▲";
45 return "asc";
46 break;
47 }
48 }
49
50 ,sort: function(th){
51 var orderby=this.marking(th);
52
53 for(var i=0;this.th[i]; i++){
54 if(this.th[i] == th){
55 var num=i;
56 break;
57 }
58 }
59
60 if(orderby == "asc"){
61 this.tr.sort(function(a,b){
62 var a2=a.getElementsByTagName("td")[num].innerHTML;
63 var b2=b.getElementsByTagName("td")[num].innerHTML;
64
65 if(this.type && this.type[num] == "number"){
66 if(!parseFloat(a2)){
67 return 1;
68 }else if(!parseFloat(b2)){
69 return -1;
70 }
71 return (parseFloat(a2) - parseFloat(b2));
72 }else{
73 return (a2.toLowerCase() > b2.toLowerCase()) ? 1 : -1;
74 }
75 }.bind(this));
76 }else{
77 this.tr.sort(function(a,b){
78 var a2=a.getElementsByTagName("td")[num].innerHTML;
79 var b2=b.getElementsByTagName("td")[num].innerHTML;
80 if(this.type && this.type[num] == "number"){
81 if(!parseFloat(a2)){
82 return 1;
83 }else if(!parseFloat(b2)){
84 return -1;
85 }
86 return (parseFloat(b2) - parseFloat(a2));
87 }else{
88 return (b2.toLowerCase() > a2.toLowerCase()) ? 1 : -1;
89 }
90 }.bind(this));
91 }
92
93 var tbody=this.table.getElementsByTagName("tbody")[0];
94 $A(tbody.childNodes).each(function(v){
95 v.parentNode.removeChild(v);
96 });
97
98 this.tr.each(function(v){
99 tbody.appendChild(v);
100 });
101 }
102 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26