-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
158 lines (153 loc) · 3.82 KB
/
index.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Selectable Table Rows with Keyboard Controls</title>
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
<link rel="stylesheet" type="text/css" media="all" href="tableSelect.css" />
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery.tableSelect.js"></script>
<script type="text/javascript">
var selectedRows = function() {
var instance = this;
if (!this.list) {
this.list=[];
}
this.add = function(row) {
list.push(row);
};
this.remove = function(row) {
for (var i=0; i<list.length;i++) {
if (list[i] == row) {
this.list.splice(i,1);
}
}
};
return(instance);
}();
$(document).ready(function() {
$('#demoTable').tableSelect({
onClick: function(row) {
//alert(row);
},
onDoubleClick: function(rows) {
$.each(rows,function(i,row) {
var name = $(row).children('td').eq(0).html() + ' ' + $(row).children('td').eq(1).html();
if ($(row).hasClass('disabled')) {
$(row).removeClass('disabled');
selectedRows.remove(name);
} else {
$(row).addClass('disabled');
selectedRows.add(name);
}
});
updateList();
},
onChange: function(row) {
//alert(row);
}
});
});
function updateList() {
$('.selectedRows').html('');
$.each(selectedRows.list,function() {
$('.selectedRows').append('<li>'+this+'</li>');
});
};
</script>
</head>
<body>
<div id="container">
<table id="demoTable" border="0" tabindex="1" cellspacing="0" cellpadding="2">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>State</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Smith</td>
<td>San Diego</td>
<td>CA</td>
</tr>
<tr>
<td>John</td>
<td>Henderson</td>
<td>San Diego</td>
<td>CA</td>
</tr>
<tr>
<td>Peter</td>
<td>Smith</td>
<td>Portland</td>
<td>OR</td>
</tr>
<tr>
<td>Greg</td>
<td>Jones</td>
<td>Los Angeles</td>
<td>CA</td>
</tr>
<tr>
<td>Susi</td>
<td>Johnson</td>
<td>San Diego</td>
<td>CA</td>
</tr>
<tr>
<td>Craig</td>
<td>Muster</td>
<td>Carlsbad</td>
<td>CA</td>
</tr>
<tr>
<td>George</td>
<td>Maffia</td>
<td>New York</td>
<td>NY</td>
</tr>
<tr>
<td>Tara</td>
<td>Lindstrom</td>
<td>Orlando</td>
<td>FL</td>
</tr>
<tr>
<td>Justin</td>
<td>Reid</td>
<td>San Marcos</td>
<td>CA</td>
</tr>
</tbody>
</table>
<div class="columnRight">
<fieldset>
<legend>Selected Rows</legend>
<ul class="selectedRows">
</ul>
</fieldset>
</div>
<div class="clear"></div><br />
<b>Keyboard Controls:</b> Ctrl, Shift, Up/Down, Enter<br />
<b>Mouse Controls:</b> Single Click, Double Click
</div>
<b>Purpose:</b>
<p>To replicate the functionality of a select box on a table so that multiple columns may be used.</p>
<b>Known Issues:</b>
<ul>
<li>Can't "tab" into the table to gain focus, must click with mouse for keyboard controls to work</li>
<li>Once row is disabled, it cannot be enabled via keyboard controls (double click still works)</li>
</ul>
<b>Browsers Support:</b>
<ul>
<li>Firefox</li>
<li>Chrome</li>
<li>Internet Explorer 7-9 (havent tested 6)</li>
</ul>
</body>
</html>