-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectFinal.html
More file actions
234 lines (194 loc) · 4.26 KB
/
ProjectFinal.html
File metadata and controls
234 lines (194 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script src="jquery.js"></script>
<script src="sorttable.js"></script>
<script type="text/javascript" src="jquery.tablescroll.js"></script>
<script>
$(document).ready(function(){
var capsnames='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var snames ='abcdefghijklmnopqrstuvwxyz';
var content
var prevcol=999;
//Generating the rows for the second table body along with random data
for(i=0; i<200; i++){
content += '<tr>'
for(j=0;j<8;j++){
if(j==0 || j==1){
var names;
names=capsnames.charAt(1 + Math.floor(Math.random() * 24));
for(v=0;v<5;v++){
names+=snames.charAt(1 + Math.floor(Math.random() * 24));
}
if (j==1 ){
random=(1 + Math.floor(Math.random() * 2));
if(random==1){
names+='@gmail.com';
}
else if(random==2){
names+='@yahoo.com';
}
}
content+='<td width =150px>' + names + '</td>'
}
else{
content+='<td width =150px>' + 1 + Math.floor(Math.random() * 50) + '</td>'
}
}
content+='</tr>';
}
$('tbody').append(content);
//This is called when a column header is clicked
$("th").click(function(){
var col = $(this).parent().children().index($(this));
rowcount=$("#sort tbody tr").length;
prevcol=sorting(rowcount,col,prevcol);
});
function sorting(rowcount,col,prevcol){
//call sortStrings for sortings the first two columns
if(col==1 || col==0){
prevcol=sortStrings(rowcount,col,prevcol);
return prevcol;
}
//call sortStrings for sortings the other columns
else
{
prevcol=sortNumbers(rowcount,col,prevcol);
return prevcol;
}
}
function sortStrings(rowcount,col,prevcol){
t=document.getElementById('sort');
var firstRow = t.getElementsByTagName('tr');
//just reverse if the column is sorted once
if (prevcol==col){
reverse(rowcount,firstRow,col);
}
//apply selection sort
else{
var prevcol=col;
for (i=0;i< rowcount-1;i++){
min=i;
for(j=i+1;j<rowcount;j++){
value1=firstRow[j].cells[col].innerHTML.toLowerCase();
value2=firstRow[min].cells[col].innerHTML.toLowerCase();
if ( value1 < value2 ){
min=j;
}
}
if (min != i){
var temp=[];
for(j=0;j<8;j++){
temp[j]=firstRow[i].cells[j].innerHTML;
}
for(k=0;k<8;k++){
firstRow[i].cells[k].innerHTML=firstRow[min].cells[k].innerHTML;
}
for(m=0;m<8;m++){
firstRow[min].cells[m].innerHTML=temp[m];
}
}
}
return prevcol;
}
}
function sortNumbers(rowcount,col,prevcol){
var sortedValues = [];
var newRows=[];
t=document.getElementById('sort');
var firstRow = t.getElementsByTagName('tr');
for(i=0;i<rowcount;i++){
var cell=firstRow[i].cells[col];
var value=cell.innerHTML;
sortedValues[i]=value;
}
if(prevcol==col){
reverse(rowcount,firstRow,col);
}
else{
prevcol=sSort(rowcount,sortedValues,firstRow,col,prevcol);
return prevcol;
}
}
function reverse(rowcount,firstRow,col){
var newRows=[];
w=rowcount-1;
for(i=0;i<rowcount;i++){
newRows[w]=firstRow[i];
w=w-1;
}
$("#sort tbody tr").remove();
$('tbody').append(newRows);
return;
}
function sSort(rowcount,sortedValues,firstRow,col,prevcol){
var i
var j
var min
var temp;
var newRows=[];
prevcol=col;
for (i=0;i< rowcount-1;i++){
min=i;
for(j=i+1;j<rowcount;j++){
if (parseInt(firstRow[j].cells[col].innerHTML) < parseInt(firstRow[min].cells[col].innerHTML)){
min=j;
}
}
if (min != i){
var temp=[];
for(j=0;j<8;j++){
temp[j]=firstRow[i].cells[j].innerHTML;
}
for(k=0;k<8;k++){
firstRow[i].cells[k].innerHTML=firstRow[min].cells[k].innerHTML;
}
for(m=0;m<8;m++){
firstRow[min].cells[m].innerHTML=temp[m];
}
}
}
return prevcol;
}
});
</script>
<div>
<table border=1 id="first" class="fixed" >
<thead id="hfixed" >
<tr id="info">
<th width =150px >NAME</th>
<th width =150px>EMAIL</th>
<th width =150px>SCORE</th>
<th width =150px>SCORE</th>
<th width =150px>SCORE</th>
<th width =150px>SCORE</th>
<th width =150px>SCORE</th>
<th width =150px>SCORE</th>
</tr>
</thead>
</table>
</div>
<div class="scroll">
<table border=1 id= "sort" class="sortable">
<tbody id "fix">
</tbody>
</table >
</div>
<style>
div.scroll
{
background-color:#00FFFF;
width:1290px;
height:600px;
overflow:scroll;
}
table.fixed thead {
background-color:#eee;
color:#666666;
font-weight: bold;
cursor: default;
}
</style>
</body>
</html>