-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
205 lines (178 loc) · 6.26 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="CraftingGamerTom">
<title>BSTable - Editable Bootstrap Table</title>
<!-- Bootstrap core CSS-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<!-- JQuery library -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
</head>
<body id="page-top" class="sidebar-toggled">
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">BSTable</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="https://github.com/CraftingGamerTom/bstable">View on Github <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="http://thomasrokicki.com">Visit Author's website <span class="sr-only">(current)</span></a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
</form>
</div>
</nav>
<main role="main" class="container" style="padding-top:60px;">
<div style="margin-top:20px;">
<h2>Example of Basic BSTable</h2>
<table class="table table-striped table-bordered" id="table1">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-top:20px;">
<h2>Example of Add New Row button, removed action label, and only some columns are editable</h2>
<button id="table2-new-row-button" class="btn btn-dark">New Row</button>
<table class="table table-striped table-bordered" id="table2">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-top:20px;">
<h2>Example of Dynamic Table with refreshing BSTable</h2>
<button id="table2-new-row-button" class="btn btn-dark" onclick="dynamicTableValuesExample()">Update Table</button>
<table class="table table-striped table-bordered" id="table3">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody id="table3-body">
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
</div>
</main><!-- /.container -->
<script src="bstable.js"></script>
<script>
// Basic example
var example1 = new BSTable("table1");
example1.init();
// Example with a add new row button & only some columns editable & removed actions column label
var example2 = new BSTable("table2", {
editableColumns:"1,2",
$addButton: $('#table2-new-row-button'),
onEdit:function(rowElement) {
console.log("EDITED:", rowElement);
let rowAsJQuery = $(rowElement);
console.log("EDITED (as jquery):", rowAsJQuery);
},
advanced: {
columnLabel: ''
}
});
example2.init();
// Example with dynamic table that requires BSTable refresh
// TODO Create method to randomly seed a random amount of rows in the table
var example3 = new BSTable("table3");
example3.init();
function dynamicTableValuesExample() {
// Generate new values for the table and show how BSTable updates
let names = ['Matt', 'John', 'Billy', 'Erica', 'Sammy', 'Tom', 'Tate', 'Emily', 'Mike', 'Bob'];
let numberOfRows = Math.floor(Math.random() * 10);
document.getElementById("table3-body").innerHTML = ''; // Clear current table
for(let i = 0; i < numberOfRows; i++) {
let randomNameIndex = Math.floor(Math.random() * 10);
let row = document.createElement("tr");
row.innerHTML = `<th scope="row">` + i + `</th><td>Value</td><td>` + names[randomNameIndex] + `</td><td>@twitter</td>`;
document.getElementById("table3-body").append(row);
}
example3.refresh();
}
</script>
</body>
</html>