-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
160 lines (133 loc) · 3.88 KB
/
demo.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
159
160
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<p class="bg-info" style="padding:15px">This is a demo for <a href="https://github.com/tomaskikutis/html-table-column-hider">https://github.com/tomaskikutis/html-table-column-hider</a>.</p>
<table class="table table-striped table-responsive" id="elements-table-1">
<caption>Chemical elements</caption>
<thead>
<tr>
<th>Symbol</th>
<th>Element</th>
<th>Group</th>
<th>Period</th>
<th>Melt</th>
<th>Boil</th>
</tr>
</thead>
<tbody>
<tr>
<td>H</td>
<td>Hydrogen</td>
<td>1</td>
<td>1</td>
<td>14.01</td>
<td>20.28</td>
</tr>
<tr>
<td>He</td>
<td>Helium</td>
<td>18</td>
<td>1</td>
<td>0.95</td>
<td>4.22</td>
</tr>
</tbody>
</table>
<form id="form-1">
<div class="form-group">
<label>
Array of column indexes to hide (1-based)
<input type="text" value="[1,2]" id="columns-to-hide-1" class="form-control" />
</label>
</div>
<button class="btn btn-default" type="submit">Apply</button>
</form>
<table class="table table-striped table-responsive" id="elements-table-2">
<caption>Hiding columns on multiple tables on single page</caption>
<thead>
<tr>
<th>Symbol</th>
<th>Element</th>
<th>Group</th>
<th>Period</th>
<th>Melt</th>
<th>Boil</th>
</tr>
</thead>
<tbody>
<tr>
<td>Li</td>
<td>Lithium</td>
<td>1</td>
<td>2</td>
<td>453.69</td>
<td>1560</td>
</tr>
<tr>
<td>Be</td>
<td>Beryllium</td>
<td>2</td>
<td>2</td>
<td>1560</td>
<td>2742</td>
</tr>
</tbody>
</table>
<form id="form-2">
<div class="form-group">
<label>
Array of column indexes to hide (1-based)
<input type="text" value="[6]" id="columns-to-hide-2" class="form-control" />
</label>
</div>
<button class="btn btn-default" type="submit">Apply</button>
</form>
</div>
<script type="text/javascript">
window.module = {};// simulate module loader
</script>
<script src="https://rawgit.com/tomaskikutis/html-table-column-hider/master/index.js"></script>
<script type="text/javascript">
var TableColumnHider = window.module.exports;// simulate module loader
var tableColumnHiderInstance1 = new TableColumnHider("#elements-table-1");
var tableColumnHiderInstance2 = new TableColumnHider("#elements-table-2");
var manageInput = function(inputValue, tableColumnHiderInstance){
try {
var columns = JSON.parse(inputValue).map(function(item){
var result = parseInt(item);
if(isNaN(result) || typeof result !== "number"){
throw new Error("number expected");
}
return parseInt(item);
});
tableColumnHiderInstance.unhideAllColumns();
tableColumnHiderInstance.hideColumns(columns);
}
catch(e){
alert("`" + inputValue + "` is not a valid array of integers.");
}
};
document.querySelector("#form-1").addEventListener("submit", function(e){
e.preventDefault();
manageInput(
document.querySelector("#columns-to-hide-1").value,
tableColumnHiderInstance1
);
});
document.querySelector("#form-2").addEventListener("submit", function(e){
e.preventDefault();
manageInput(
document.querySelector("#columns-to-hide-2").value,
tableColumnHiderInstance2
);
});
</script>
</body>
</html>