| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Dragtable Mod (beta)</title> |
| 6 |
|
| 7 |
|
| 8 |
<script src="js/jquery-latest.min.js"></script> |
| 9 |
<script src="js/jquery-ui.min.js"></script> |
| 10 |
|
| 11 |
|
| 12 |
<link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css"> |
| 13 |
<link rel="stylesheet" href="css/bootstrap-v3.min.css"> |
| 14 |
<link rel="stylesheet" href="css/jq.css"> |
| 15 |
<link href="css/prettify.css" rel="stylesheet"> |
| 16 |
<script src="js/prettify.js"></script> |
| 17 |
<script src="js/docs.js"></script> |
| 18 |
<style> |
| 19 |
/* override jQuery UI overriding Bootstrap */ |
| 20 |
.accordion .ui-widget-content a { |
| 21 |
color: #337ab7; |
| 22 |
} |
| 23 |
</style> |
| 24 |
|
| 25 |
|
| 26 |
<link class="theme" rel="stylesheet" href="../css/theme.blue.css"> |
| 27 |
<link rel="stylesheet" href="../css/dragtable.mod.css"> |
| 28 |
|
| 29 |
|
| 30 |
<script src="../js/jquery.tablesorter.js"></script> |
| 31 |
<script src="../js/jquery.tablesorter.widgets.js"></script> |
| 32 |
|
| 33 |
<script src="../js/extras/jquery.dragtable.mod.js"></script> |
| 34 |
|
| 35 |
<style id="css">/* optional styling */ |
| 36 |
caption { |
| 37 |
/* override bootstrap adding 8px to the top & bottom of the caption */ |
| 38 |
padding: 0; |
| 39 |
} |
| 40 |
.ui-sortable-placeholder { |
| 41 |
/* change placeholder (seen while dragging) background color */ |
| 42 |
background: #ddd; |
| 43 |
} |
| 44 |
div.table-handle-disabled { |
| 45 |
/* optional red background color indicating a disabled drag handle */ |
| 46 |
background-color: rgba(255,128,128,0.5); |
| 47 |
/* opacity set to zero for disabled handles in the dragtable.mod.css file */ |
| 48 |
opacity: 0.7; |
| 49 |
} |
| 50 |
/* fix cursor */ |
| 51 |
.tablesorter-blue .tablesorter-header { |
| 52 |
cursor: default; |
| 53 |
} |
| 54 |
.sorter { |
| 55 |
cursor: pointer; |
| 56 |
}</style> |
| 57 |
<script id="js">$(function () { |
| 58 |
$('table') |
| 59 |
// initialize dragtable FIRST! |
| 60 |
.dragtable({ |
| 61 |
// *** new dragtable mod options *** |
| 62 |
// this option MUST match the tablesorter selectorSort option! |
| 63 |
sortClass: '.sorter', |
| 64 |
// this function is called after everything has been updated |
| 65 |
tablesorterComplete: function(table) {}, |
| 66 |
|
| 67 |
// *** original dragtable settings (non-default) *** |
| 68 |
dragaccept: '.drag-enable', // class name of draggable cols -> default null = all columns draggable |
| 69 |
|
| 70 |
// *** original dragtable settings (default values) *** |
| 71 |
revert: false, // smooth revert |
| 72 |
dragHandle: '.table-handle', // handle for moving cols, if not exists the whole 'th' is the handle |
| 73 |
maxMovingRows: 40, // 1 -> only header. 40 row should be enough, the rest is usually not in the viewport |
| 74 |
excludeFooter: false, // excludes the footer row(s) while moving other columns. Make sense if there is a footer with a colspan. */ |
| 75 |
onlyHeaderThreshold: 100, // TODO: not implemented yet, switch automatically between entire col moving / only header moving |
| 76 |
persistState: null, // url or function -> plug in your custom persistState function right here. function call is persistState(originalTable) |
| 77 |
restoreState: null, // JSON-Object or function: some kind of experimental aka Quick-Hack TODO: do it better |
| 78 |
exact: true, // removes pixels, so that the overlay table width fits exactly the original table width |
| 79 |
clickDelay: 10, // ms to wait before rendering sortable list and delegating click event |
| 80 |
containment: null, // @see http://api.jqueryui.com/sortable/#option-containment, use it if you want to move in 2 dimesnions (together with axis: null) |
| 81 |
cursor: 'move', // @see http://api.jqueryui.com/sortable/#option-cursor |
| 82 |
cursorAt: false, // @see http://api.jqueryui.com/sortable/#option-cursorAt |
| 83 |
distance: 0, // @see http://api.jqueryui.com/sortable/#option-distance, for immediate feedback use "0" |
| 84 |
tolerance: 'pointer', // @see http://api.jqueryui.com/sortable/#option-tolerance |
| 85 |
axis: 'x', // @see http://api.jqueryui.com/sortable/#option-axis, Only vertical moving is allowed. Use 'x' or null. Use this in conjunction with the 'containment' setting |
| 86 |
beforeStart: $.noop, // returning FALSE will stop the execution chain. |
| 87 |
beforeMoving: $.noop, |
| 88 |
beforeReorganize: $.noop, |
| 89 |
beforeStop: $.noop |
| 90 |
}) |
| 91 |
// initialize tablesorter |
| 92 |
.tablesorter({ |
| 93 |
theme: 'blue', |
| 94 |
// this option MUST match the dragtable sortClass option! |
| 95 |
selectorSort: '.sorter', |
| 96 |
widgets: ['zebra', 'filter', 'columns'] |
| 97 |
}); |
| 98 |
});</script> |
| 99 |
|
| 100 |
</head> |
| 101 |
<body> |
| 102 |
|
| 103 |
<div id="banner"> |
| 104 |
<h1>table<em>sorter</em></h1> |
| 105 |
<h2>Dragtable Mod (beta)</h2> |
| 106 |
<h3>Flexible client-side table sorting</h3> |
| 107 |
<a href="index.html">Back to documentation</a> |
| 108 |
</div> |
| 109 |
|
| 110 |
<div id="main"> |
| 111 |
<p></p> |
| 112 |
<br> |
| 113 |
<div id="root" class="accordion"> |
| 114 |
|
| 115 |
<h3 id="notes"><a href="#">Notes</a></h3> |
| 116 |
<div> |
| 117 |
<ul> |
| 118 |
<li>This demo uses a modified version of the <a href="http://akottr.github.io/dragtable/">jQuery UI Dragtable widget</a> (beta) to work with tablesorter.</li> |
| 119 |
<li>This mod <strong>has been</strong> tested with the following widgets: <span class="good">alignChar</span>, <span class="good">columns</span>, <span class="good">cssStickyHeaders</span>, <span class="good">editable</span>, <span class="good">filter</span>, <span class="good">grouping</span>, <span class="good">headerTitles</span>, <span class="good">math</span>, <span class="good">output</span>, <span class="good">pager</span> <span class="good">print</span>, <span class="good">reflow</span>, <span class="good">resizable</span>, <span class="good">repeatHeaders</span>, <span class="good">staticRow</span>, <span class="good">uitheme</span> & <span class="good">zebra</span>.</li> |
| 120 |
<li>This mod <strong><em>does not</em></strong> currently work with the following widgets: |
| 121 |
<ul> |
| 122 |
<li><span class="bad">chart</span> - needs more work to be compatible.</li> |
| 123 |
<li><span class="bad">columnSelector</span> - needs more work - making this compatible will require significant changes to the dragtable core.</li> |
| 124 |
<li><span class="bad">saveSort</span> - this saves the newly moved sorted column properly, but on page reload the column order is restored so it sorts the incorrect column.</li> |
| 125 |
<li><span class="bad">scroller</span> - way too much work to make this compatible.</li> |
| 126 |
<li><span class="bad">stickyHeaders</span> - needs more work - can't get the drag handle in the cloned sticky header from passing the mousedown on to the original drag handle.</li> |
| 127 |
</ul> |
| 128 |
</li> |
| 129 |
<li>Any widgets not listed above can be assumed to be incompatible, for now.</li> |
| 130 |
</ul> |
| 131 |
</div> |
| 132 |
|
| 133 |
<h3 id="setup"><a href="#">Tablesorter setup</a></h3> |
| 134 |
<div> |
| 135 |
A complete javascript example can be found in the demo section, below the table. |
| 136 |
<p></p> |
| 137 |
To use this mod: |
| 138 |
<ul> |
| 139 |
<li>Initialize the dragtable mod script first, then initialize tablesorter.</li> |
| 140 |
<li><span class="label label-warning">Warning!</span> When setting up the initialization code, make sure that the dragtable <code>sortClass</code> option <em>exactly matches</em> the tablesorter <code>selectorSort</code> option, or the table will be unsortable. |
| 141 |
<pre class="prettyprint lang-js">$('table') |
| 142 |
.dragtable({ sortClass: '.sorter' }) // this is already the default value |
| 143 |
.tablesorter({ selectorSort: '.sorter' }); // this default value is 'th, td'</pre></li> |
| 144 |
<li><span class="label warning">Warning!</span> Do not reference a column using jQuery data (e.g. <code>$('th:contains(Name)').data('sorter', 'text');</code>) or by it's zero-based index<sup class="bright">(1)</sup> because these references do not get updated after a column move! |
| 145 |
<p></p> |
| 146 |
Instead, use one of the following methods (these examples set the column parser): |
| 147 |
<h4>Set parser by data-attribute or header class</h4> |
| 148 |
<pre class="prettyprint lang-html"><tr> |
| 149 |
<th class="col-id" data-sorter="digit">...</th> <!-- parser set by data-attribute --> |
| 150 |
<th class="col-name drag-enable sorter-text">...</th> <!-- parser set by header class --> |
| 151 |
<th class="col-date drag-enable">...</th> <!-- parser set by headers option (see below) --> |
| 152 |
</tr></pre> |
| 153 |
<h4>Or, set parser by <code>headers</code> option</h4> |
| 154 |
<pre class="prettyprint lang-js">$('table').tablesorter({ |
| 155 |
headers : { |
| 156 |
'.col-date' : { sorter : 'shortDate' } |
| 157 |
} |
| 158 |
});</pre></li> |
| 159 |
<li>In order to get dragtable to work, the mod will add a div to act as a dragable handle and wrap the header text in a div<sup class="bright">(2)</sup> which needs to be targeted by the <code>selectorSort</code> option to make it clickable for sorting. |
| 160 |
<p></p> |
| 161 |
The <em>resulting HTML</em> may look like this: |
| 162 |
<pre class="prettyprint lang-html"><tr> |
| 163 |
<th class="col-id" data-sorter="digit"> |
| 164 |
<div class="table-handle-disabled"></div> |
| 165 |
<!-- clicking on the "sort" wrapper below will not trigger a sort, because the cell is not set to sort --> |
| 166 |
<div class="sorter">9999</div> |
| 167 |
</th> |
| 168 |
<th class="col-name sorter-text drag-enable"> |
| 169 |
<div class="table-handle"></div> |
| 170 |
<div class="sorter">Name</div> |
| 171 |
</th> |
| 172 |
<th class="col-date drag-enable"> |
| 173 |
<div class="table-handle"></div> |
| 174 |
<div class="sorter">1/1/2015</div> |
| 175 |
</th> |
| 176 |
</tr></pre> |
| 177 |
</li> |
| 178 |
</ul> |
| 179 |
<span class="bright">(1)</span> Options that use a column index (such as the <code>sortList</code>), or an array of settings (like the <code>resizable_widths</code> option) are updated internally by the mod. |
| 180 |
<p></p> |
| 181 |
<span class="bright">(2)</span> The class name for the dragable handle is set by the dragtable <code>dragHandle</code> option & the class name for the clickable div wrapping the header text is set by the dragtable <code>sortClass</code> option. |
| 182 |
</div> |
| 183 |
|
| 184 |
</div> |
| 185 |
|
| 186 |
<h1>Demo</h1> |
| 187 |
<div id="demo"><table class="tablesorter"> |
| 188 |
<caption>Student Grades</caption> |
| 189 |
<thead> |
| 190 |
<tr> |
| 191 |
<th>Name (0)</th> |
| 192 |
<th class="drag-enable">Major (1)</th> |
| 193 |
<th class="drag-enable">Sex (2)</th> |
| 194 |
<th class="drag-enable">English (3)</th> |
| 195 |
<th class="drag-enable">Japanese (4)</th> |
| 196 |
<th class="drag-enable">Calculus (5)</th> |
| 197 |
<th class="drag-enable">Geometry (6)</th> |
| 198 |
</tr> |
| 199 |
</thead> |
| 200 |
<tfoot> |
| 201 |
<tr><th>Name</th><th>Major</th><th>Sex</th><th>English</th><th>Japanese</th><th>Calculus</th><th>Geometry</th></tr> |
| 202 |
</tfoot> |
| 203 |
<tbody> |
| 204 |
<tr><td>Student01 (0)</td><td>Languages (1)</td><td>male (2)</td><td>80 (3)</td><td>70 (4)</td><td>75 (5)</td><td>80 (6)</td></tr> |
| 205 |
<tr><td>Student02</td><td>Mathematics</td><td>male</td><td>90</td><td>88</td><td>100</td><td>90</td></tr> |
| 206 |
<tr><td>Student03</td><td>Languages</td><td>female</td><td>85</td><td>95</td><td>80</td><td>85</td></tr> |
| 207 |
<tr><td>Student04</td><td>Languages</td><td>male</td><td>60</td><td>55</td><td>100</td><td>100</td></tr> |
| 208 |
<tr><td>Student05</td><td>Languages</td><td>female</td><td>68</td><td>80</td><td>95</td><td>80</td></tr> |
| 209 |
<tr><td>Student06</td><td>Mathematics</td><td>male</td><td>100</td><td>99</td><td>100</td><td>90</td></tr> |
| 210 |
<tr><td>Student07</td><td>Mathematics</td><td>male</td><td>85</td><td>68</td><td>90</td><td>90</td></tr> |
| 211 |
<tr><td>Student08</td><td>Languages</td><td>male</td><td>100</td><td>90</td><td>90</td><td>85</td></tr> |
| 212 |
<tr><td>Student09</td><td>Mathematics</td><td>male</td><td>80</td><td>50</td><td>65</td><td>75</td></tr> |
| 213 |
<tr><td>Student10</td><td>Languages</td><td>male</td><td>85</td><td>100</td><td>100</td><td>90</td></tr> |
| 214 |
<tr><td>Student11</td><td>Languages</td><td>male</td><td>86</td><td>85</td><td>100</td><td>100</td></tr> |
| 215 |
<tr><td>Student12</td><td>Mathematics</td><td>female</td><td>100</td><td>75</td><td>70</td><td>85</td></tr> |
| 216 |
<tr><td>Student13</td><td>Languages</td><td>female</td><td>100</td><td>80</td><td>100</td><td>90</td></tr> |
| 217 |
<tr><td>Student14</td><td>Languages</td><td>female</td><td>50</td><td>45</td><td>55</td><td>90</td></tr> |
| 218 |
<tr><td>Student15</td><td>Languages</td><td>male</td><td>95</td><td>35</td><td>100</td><td>90</td></tr> |
| 219 |
<tr><td>Student16</td><td>Languages</td><td>female</td><td>100</td><td>50</td><td>30</td><td>70</td></tr> |
| 220 |
<tr><td>Student17</td><td>Languages</td><td>female</td><td>80</td><td>100</td><td>55</td><td>65</td></tr> |
| 221 |
<tr><td>Student18</td><td>Mathematics</td><td>male</td><td>30</td><td>49</td><td>55</td><td>75</td></tr> |
| 222 |
<tr><td>Student19</td><td>Languages</td><td>male</td><td>68</td><td>90</td><td>88</td><td>70</td></tr> |
| 223 |
<tr><td>Student20</td><td>Mathematics</td><td>male</td><td>40</td><td>45</td><td>40</td><td>80</td></tr> |
| 224 |
</tbody> |
| 225 |
</table></div> |
| 226 |
|
| 227 |
<h1>HTML</h1> |
| 228 |
<div id="html"> |
| 229 |
<pre class="prettyprint lang-html"></pre> |
| 230 |
</div> |
| 231 |
|
| 232 |
<h1>Javascript</h1> |
| 233 |
<div id="javascript"> |
| 234 |
<pre class="prettyprint lang-javascript"></pre> |
| 235 |
</div> |
| 236 |
|
| 237 |
<h1>Optional CSS</h1> |
| 238 |
<div id="css"> |
| 239 |
<pre class="prettyprint lang-css"></pre> |
| 240 |
</div> |
| 241 |
|
| 242 |
</div> |
| 243 |
|
| 244 |
</body> |
| 245 |
</html> |