Debian Codegraph @

docs/example-widget-static-row.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Static Row Widget</title>
6
7 <!-- jQuery -->
8 <script src="js/jquery-latest.min.js"></script>
9
10 <!-- Demo stuff -->
11 <link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
12 <script src="js/jquery-ui.min.js"></script>
13 <link rel="stylesheet" href="css/jq.css">
14 <link href="css/prettify.css" rel="stylesheet">
15 <script src="js/prettify.js"></script>
16 <script src="js/docs.js"></script>
17
18 <!-- Tablesorter: required -->
19 <link rel="stylesheet" href="../css/theme.blue.css">
20 <script src="../js/jquery.tablesorter.js"></script>
21 <script src="../js/widgets/widget-staticRow.js"></script>
22 <style>
23 .options th:not(.sorter-false) {
24 width: 10%;
25 }
26 #alphimals * {
27 font-size: 12px;
28 line-height: 12px;
29 }
30 </style>
31 <style id="css">#alphimals td {
32 text-align: center;
33 }
34 .tablesorter tbody tr.static td {
35 background-color: #999;
36 color: #fff;
37 }</style>
38
39 <script id="js">$(function() {
40
41 $('#alphimals, #table2').tablesorter({
42 theme: 'blue',
43 widgets: ['zebra', 'staticRow']
44 })
45 // (ctrl or mac command) + click to toggle static row
46 .find('tbody tr').click(function(event) {
47 if (event.ctrlKey || event.metaKey) {
48 $(this)
49 .toggleClass('static')
50 .trigger('staticRowsRefresh');
51 }
52 });
53
54 $('.addrow').click(function() {
55 $('#alphimals tbody')
56 .append('<tr><td>AA</td><td>0</td><td>Aardvark</td></tr>')
57 .trigger('update');
58 });
59
60 // move row up or down
61 $('.move').click(function() {
62 var direction = $(this).hasClass('up'),
63 $rows = $('#alphimals tr'),
64 $ig = $rows.filter(':contains(Iguana)').addClass('static'),
65 len = $rows.length - 3, // subtract two because there are two other static rows
66 v = $ig.data('row-index');
67 v = direction ? --v : ++v;
68 v = v > len ? len : v <= 0 ? 0 : v;
69 $ig.data('row-index', v);
70 $rows.trigger('staticRowsRefresh');
71 });
72
73 });</script>
74 </head>
75 <body>
76 <div id="banner">
77 <h1>table<em>sorter</em></h1>
78 <h2>Static Row Widget</h2>
79 <h3>Flexible client-side table sorting</h3>
80 <a href="index.html">Back to documentation</a>
81 </div>
82 <div id="main">
83
84 <p></p>
85 <br>
86 <div class="accordion">
87
88 <h3 id="notes"><a href="#">Notes</a></h3>
89 <div>
90 <ul>
91 <li>
92 In <span class="version">v2.19.1</span>, the <code>staticRow_event</code> option was added.
93 <p></p>
94 </li>
95 <li>This widget will only work in tablesorter version 2.8+.</li>
96 <li>The widget was modified from <a href="https://github.com/ascii-soup/Tablesorter-Static-Row-Plugin">Tablesorter-Static-Row-Plugin</a> by <a href="https://github.com/ascii-soup">ascii-soup</a> (<a href="https://github.com/ascii-soup/Tablesorter-Static-Row-Plugin/blob/master/LICENSE">MIT license</a>).</li>
97 <li>It has been updated to work in tables with multiple tbodies, but not within information-only tbodies.</li>
98 <li>This widget was not tested, nor was it meant to be used with the pager.</li>
99 <li><span class="label label-info">Note</span> This demo was updated to allow toggling of static rows.</li>
100 </ul>
101 </div>
102
103 <h3><a href="#">Options</a></h3>
104 <div>
105 <h3>Group widget default options (added inside of tablesorter <code>widgetOptions</code>)</h3>
106 <div class="tip">
107 <span class="label label-info">TIP!</span> Click on the link in the option column to reveal full details (or <a href="#" class="toggleAll">toggle</a>|<a href="#" class="showAll">show</a>|<a href="#" class="hideAll">hide</a> all) or double click to update the browser location.
108 </div>
109 <table class="tablesorter-blue options">
110 <thead>
111 <tr><th>Option</th><th>Default</th><th class="sorter-false">Description</th></tr>
112 </thead>
113 <tbody>
114 <tr id="staticrow_class">
115 <td><span class="permalink">staticRow_class</span></td>
116 <td><code>&quot;.static&quot;</code></td>
117 <td>
118 Set a class name to use to lock a row in place, include a period.
119 </td>
120 </tr>
121
122 <tr id="staticrow_data">
123 <td><span class="permalink">staticRow_data</span></td>
124 <td><code>&quot;static-index&quot;</code></td>
125 <td>
126 Set the jQuery data name to use with the row element. This data name saves the row index, and is only available as an option to avoid conflicts.
127 </td>
128 </tr>
129
130 <tr id="staticrow_event">
131 <td><span class="permalink">staticRow_event</span></td>
132 <td><code>&quot;staticRowsRefresh&quot;</code></td>
133 <td>
134 Set the event that the widget listens for to perform a refresh.
135 </td>
136 </tr>
137
138 <tr id="staticrow_index">
139 <td><a href="#" class="permalink">staticRow_index</a></td>
140 <td><code>&quot;row-index&quot;</code></td>
141 <td>
142 Use this data-attribute to set the desired static row location
143 <div class="collapsible">
144 <br>
145 Set the desired location using either of these two methods:
146 <ul>
147 <li>
148 Use a zero-based index of the row
149 <pre class="prettyprint lang-html">&lt;tr data-row-index=&quot;5&quot;&gt;...&lt;/tr&gt;</pre>
150 <span class="label label-info">Note</span> setting this index to much more than the number of table rows ensures that it will stay at the bottom when adding new rows.<br>
151 <br>
152 </li>
153 <li>
154 Use a percentage if total rows within it's tbody
155 <pre class="prettyprint lang-html">&lt;tr data-row-index=&quot;50%&quot;&gt;...&lt;/tr&gt;</pre>
156 </li>
157 </ul>
158 These values take priority over the actual row index, so as shown in the "Single tbody" demo below, the header row is set to 50%, but initially, it is located at the top of the table.<br>
159 <br>
160 If these values are changed dynamically, the static row location can be updated
161 </div>
162 </td>
163 </tr>
164
165 </tbody>
166 </table>
167 </div>
168
169 <h3><a href="#">Methods / Events</a></h3>
170 <div>
171 <h3>Method</h3>
172 If adding or removing rows from the table, using any of the update methods will automatically refresh the static row indexes. Use the "Add Row" button below to test this.<br>
173 <br>
174 To modify or refresh the static row indexing without updating, trigger a <code>staticRowsRefresh</code> event on the table:
175 <pre class="prettyprint lang-js">var $row = $("tr:contains('Iguana')");
176 // move Iguana row down one (remember, this only works on static rows)
177 $row.data('row-index', $row.data('row-index') + 1);
178 $(table).trigger('staticRowsRefresh');</pre>
179 this allows moving a static row dynamically; try the Move "Ignuana" row buttons above the "Single tbody" demo.
180 <h3>Event</h3>
181 A <code>staticRowsComplete</code> event is triggered after the static rows widget has completed moving the static rows back into place. Use it as follows:
182 <pre class="prettyprint lang-js">$(table).bind('staticRowsComplete', function(table) {
183 console.log('static rows applied to ' + table.id);
184 });</pre>
185 </div>
186
187 </div>
188
189 <h1>Demo</h1>
190 <span class="label label-info">Note</span> Make any row static or normal by toggling the <code>static</code> class name using <kbd>Ctrl</kbd> + left click (<kbd>&#8984;</kbd> + click on Mac)<br>
191 <div id="demo"><h3>Single tbody</h3>
192 <p><button type="button" class="addrow">Add Row</button> Move "Iguana" row: <button type="button" class="move up">up</button> <button type="button" class="move">down</button></p>
193 <table id="alphimals" class="tablesorter">
194 <thead>
195 <tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>
196 </thead>
197 <tbody>
198 <tr class="static" data-row-index="50%"><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>
199 <tr><td>D</td><td>4</td><td>Dog</td></tr>
200 <tr><td>E</td><td>5</td><td>Emu</td></tr>
201 <tr><td>F</td><td>6</td><td>Frog</td></tr>
202 <tr><td>G</td><td>7</td><td>Goat</td></tr>
203 <tr><td>A</td><td>1</td><td>Anteater</td></tr>
204 <tr><td>B</td><td>2</td><td>Bear</td></tr>
205 <tr><td>C</td><td>3</td><td>Cat</td></tr>
206 <tr><td>H</td><td>8</td><td>Horse</td></tr>
207 <!-- index of next row set to one less because of static row above set to 50% -->
208 <tr class="static" data-row-index="8"><td>I</td><td>9</td><td>Iguana</td></tr>
209 <tr><td>J</td><td>10</td><td>Jellyfish</td></tr>
210 <tr><td>V</td><td>22</td><td>Vole</td></tr>
211 <tr><td>W</td><td>23</td><td>Walrus</td></tr>
212 <tr><td>X</td><td>24</td><td>Xantis</td></tr>
213 <tr><td>K</td><td>11</td><td>Koala</td></tr>
214 <tr><td>L</td><td>12</td><td>Lemur</td></tr>
215 <tr><td>Q</td><td>17</td><td>Quail</td></tr>
216 <tr><td>R</td><td>18</td><td>Rhino</td></tr>
217 <tr><td>S</td><td>19</td><td>Seal</td></tr>
218 <tr><td>M</td><td>13</td><td>Mink</td></tr>
219 <tr><td>N</td><td>14</td><td>Nightingale</td></tr>
220 <tr><td>O</td><td>15</td><td>Octopus</td></tr>
221 <tr><td>P</td><td>16</td><td>Pig</td></tr>
222 <tr><td>T</td><td>20</td><td>Tiger</td></tr>
223 <tr><td>U</td><td>21</td><td>Urchin</td></tr>
224 <tr><td>Y</td><td>25</td><td>Yak</td></tr>
225 <tr><td>Z</td><td>26</td><td>Zebra</td></tr>
226 <tr class="static" data-row-index="50"><td>Total Count</td><td>Lots!</td><td>&nbsp;</td></tr>
227 </tbody>
228 </table>
229
230 <h4>Multiple tbody</h4>
231 <table id="table2" class="tablesorter">
232 <thead>
233 <tr>
234 <th>Rank</th>
235 <th>First Name</th>
236 <th>Last Name</th>
237 <th>Age</th>
238 <th>Total</th>
239 <th>Discount</th>
240 <th>Date</th>
241 </tr>
242 </thead>
243 <tbody>
244 <tr><td>1</td><td>Philip Aaron Wong</td><td>Johnson Sr Esq</td><td>25</td><td>$5.95</td><td>22%</td><td>Jun 26, 2004 7:22 AM</td></tr>
245 <tr><td>11</td><td>Aaron</td><td>Hibert</td><td>12</td><td>$2.99</td><td>5%</td><td>Aug 21, 2009 12:21 PM</td></tr>
246 <tr class="static"><td>12</td><td>Brandon Clark</td><td>Henry Jr</td><td>51</td><td>$42.29</td><td>18%</td><td>Oct 13, 2000 1:15 PM</td></tr>
247 <tr><td>111</td><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr>
248 <tr><td>21</td><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>
249 <tr><td>013</td><td>Clark</td><td>Kent Sr.</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>
250 </tbody>
251 <tbody class="tablesorter-infoOnly">
252 <tr><th colspan="7">Second tbody</th></tr>
253 </tbody>
254 <tbody>
255 <tr><td>005</td><td>Bruce</td><td>Almighty Esq</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2021 9:12 AM</td></tr>
256 <tr><td>10</td><td>Alex</td><td>Dumass</td><td>13</td><td>$5.29</td><td>4%</td><td>Jan 8, 2012 5:11 PM</td></tr>
257 <tr><td>16</td><td>Jim</td><td>Franco</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2004 11:23 AM</td></tr>
258 <tr><td>166</td><td>Bruce Lee</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td></tr>
259 <tr><td>100</td><td>Brenda Dexter</td><td>McMasters</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2010 7:23 PM</td></tr>
260 <tr><td>55</td><td>Dennis</td><td>Bronson</td><td>65</td><td>$123.00</td><td>32%</td><td>Jan 20, 2001 1:12 PM</td></tr>
261 <tr class="static"><td>9</td><td>Martha</td><td>delFuego</td><td>25</td><td>$22.09</td><td>17%</td><td>Jun 11, 2011 10:55 AM</td></tr>
262 </tbody>
263 </table>
264
265 <h1>Javascript</h1>
266 <div id="javascript">
267 <pre class="prettyprint lang-javascript"></pre>
268 </div>
269 <h1>CSS</h1>
270 <div id="css">
271 <pre class="prettyprint lang-css"></pre>
272 </div>
273 <h1>HTML</h1>
274 <div id="html">
275 <pre class="prettyprint lang-html"></pre>
276 </div>
277
278 </div>
279 </div>
280
281 </body>
282 </html>