mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
added widget priorities
This commit is contained in:
parent
c030e8ebbb
commit
5c4fe06b81
@ -22,7 +22,8 @@ Default Theme
|
|||||||
border-bottom: #ccc 2px solid;
|
border-bottom: #ccc 2px solid;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
.tablesorter-default tfoot th {
|
.tablesorter-default tfoot th,
|
||||||
|
.tablesorter-default tfoot td {
|
||||||
border: 0;
|
border: 0;
|
||||||
}
|
}
|
||||||
.tablesorter-default .header,
|
.tablesorter-default .header,
|
||||||
|
@ -96,21 +96,19 @@ $(function() {
|
|||||||
<em>NOTE!</em>
|
<em>NOTE!</em>
|
||||||
<ul>
|
<ul>
|
||||||
<li>This widget can be applied to the original plugin. The code is in the "jquery.tablesorter.widgets.js" file.</li>
|
<li>This widget can be applied to the original plugin. The code is in the "jquery.tablesorter.widgets.js" file.</li>
|
||||||
<li>You will need to modify the <code>headerTemplate</code> option to include the jQuery UI icon! See the example in the code. <span class="tip"><em>New!</em></span> v2.7!</li>
|
<li>Added a widget option named <code>stickyHeaders_cloneId</code> <span class="tip"><em>New!</em></span> v2.9!
|
||||||
<li>Scroll down the page to see the headers stick. Then sort the columns using the sticky headers!</li>
|
|
||||||
<li>Added <code>widgetOptions.stickyHeader</code> option which contains the css class name applied to the actual sticky header. <span class="tip"><em>New! v2.1</em></span></li>
|
|
||||||
<li>Multiple rows in the header will become sticky. <span class="tip"><em>New! v2.1.17</em></span></li>
|
|
||||||
<li>The filter widget adds a row to the table header, but that row will not be included in the sticky header.</li>
|
|
||||||
<li>Add the class name <code>sticky-false</code> to any header rows you don't want to become sticky. <span class="tip"><em>New! v2.1.18</em></span></li>
|
|
||||||
<li><del>Because of an issue with jQuery version 1.3 and older causing an error, this widget needs at least jQuery version 1.4+ in order to work.</del> Now working with jQuery 1.2.6+ again.</li>
|
|
||||||
<li>Because of the limitations of Internet Explorer version 7 and older, this widget will not work.</li>
|
|
||||||
<li><del>For the sticky header to work properly if any <code><TD></code>'s are included within the header:</del> <span class="tip"><em>Fixed! v2.4</em></span>
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><del>Set the <code>selectorHeaders</code> option to <code>thead th, thead td</code>.</del></li>
|
<li>It contains a suffix to add to any table id.</li>
|
||||||
<li><del>The <code><TD></code> may not be styled properly, so CSS changes may be needed.</del></li>
|
<li>Its default value is <code>-sticky</code> </li>
|
||||||
<li><del>To prevent the <code><TD></code> from being sortable, add a <code>sorter-false</code> class name.</del></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<li>You will need to modify the <code>headerTemplate</code> option to include the jQuery UI icon! See the example in the code. <span class="tip"><em>New!</em></span> v2.7!</li>
|
||||||
|
<li>Scroll down the page to see the headers stick. Then sort the columns using the sticky headers!</li>
|
||||||
|
<li>Added a widget option named <code>stickyHeader</code> option which contains the css class name applied to the actual sticky header (v2.1).</li>
|
||||||
|
<li>Multiple rows in the header will become sticky (v2.1.17).</li>
|
||||||
|
<li>The filter widget adds a row to the table header, but that row will not be included in the sticky header.</li>
|
||||||
|
<li>Add the class name <code>sticky-false</code> to any header rows you don't want to become sticky (v2.1.18).</li>
|
||||||
|
<li>Because of the limitations of Internet Explorer version 7 and older, this widget will not work.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -126,13 +124,8 @@ $(function() {
|
|||||||
</select>
|
</select>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
<table class="tablesorter" borderspacing="10">
|
<table class="tablesorter">
|
||||||
<caption>Table caption</caption>
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
|
||||||
<th colspan="3" class="sorter-false">Personal Information for each person (resize the browser to check expanding height)</th>
|
|
||||||
<td colspan="4" class="sorter-false">Courses (this is a TD cell)</td>
|
|
||||||
</tr>
|
|
||||||
<tr><th>Name</th><th>Major</th><th>Sex</th><th>English</th><th>Japanese</th><th>Calculus</th><th class="filter-false sorter-false">Geometry</th></tr>
|
<tr><th>Name</th><th>Major</th><th>Sex</th><th>English</th><th>Japanese</th><th>Calculus</th><th class="filter-false sorter-false">Geometry</th></tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
|
@ -26,42 +26,42 @@
|
|||||||
// ************************************
|
// ************************************
|
||||||
$.tablesorter.addWidget({
|
$.tablesorter.addWidget({
|
||||||
|
|
||||||
// give the widget an id
|
|
||||||
id: "repeatHeaders",
|
id: "repeatHeaders",
|
||||||
|
priority: 10,
|
||||||
options: {
|
options: {
|
||||||
rowsToSkip : 4
|
rowsToSkip : 4
|
||||||
},
|
},
|
||||||
// format is called on init and when a sorting has finished
|
// format is called on init and when a sorting has finished
|
||||||
format: function(table, c, wo) {
|
format: function(table, c, wo) {
|
||||||
var h, i, skip;
|
var h = '', i, $tr, l, skip;
|
||||||
// cache and collect all TH headers
|
// cache and collect all TH headers
|
||||||
if (!this.headers) {
|
if (!wo.repeatHeaders) {
|
||||||
h = this.headers = [];
|
h = '<tr class="repeated-header remove-me">';
|
||||||
$("thead th",table).each(function() {
|
$.each(c.headerContent, function(i,t) {
|
||||||
h.push( "<th>" + $(this).text() + "</th>" );
|
h += '<th>' + t + '</th>';
|
||||||
});
|
});
|
||||||
|
// "remove-me" class was added in case the table needs to be updated, the "remove-me" rows will be
|
||||||
|
// removed prior to the update to prevent including the rows in the update - see "selectorRemove" option
|
||||||
|
wo.repeatHeaders = h + '</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove appended headers by classname
|
|
||||||
$(table).find("tr.repeated-header").remove();
|
|
||||||
|
|
||||||
// number of rows to skip
|
// number of rows to skip
|
||||||
skip = wo && wo.rowsToSkip || 4;
|
skip = wo && wo.rowsToSkip || 4;
|
||||||
|
|
||||||
|
// remove appended headers by classname
|
||||||
|
c.$table.find("tr.repeated-header").remove();
|
||||||
|
$tr = c.$tbodies.find('tr');
|
||||||
|
l = $tr.length;
|
||||||
// loop all tr elements and insert a copy of the "headers"
|
// loop all tr elements and insert a copy of the "headers"
|
||||||
for (i = skip; i < table.tBodies[0].rows.length; i += (skip + 1)) {
|
for (i = skip; i < l; i += skip) {
|
||||||
// insert a copy of the table head every X rows
|
// insert a copy of the table head every X rows
|
||||||
$("tbody tr:eq(" + i + ")",table).before(
|
$tr.eq(i).before(wo.repeatHeaders);
|
||||||
// "remove-me" class was added in case the table needs to be updated, the "remove-me" rows will be
|
|
||||||
// removed prior to the update to prevent including the rows in the update - see "selectorRemove" option
|
|
||||||
$("<tr></tr>").addClass("repeated-header remove-me").html(this.headers.join(""))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// this remove function is called when using the refreshWidgets method or when destroying the tablesorter plugin
|
// this remove function is called when using the refreshWidgets method or when destroying the tablesorter plugin
|
||||||
// this function only applies to tablesorter v2.4+
|
// this function only applies to tablesorter v2.4+
|
||||||
remove: function(table, c, wo){
|
remove: function(table, c){
|
||||||
$(table).find("tr.repeated-header").remove();
|
c.$table.find("tr.repeated-header").remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -91,6 +91,13 @@
|
|||||||
Notes about the <code>addWidget</code> template:
|
Notes about the <code>addWidget</code> template:
|
||||||
<ul>
|
<ul>
|
||||||
<li>The <code>id</code> block is required and must be unique.</li>
|
<li>The <code>id</code> block is required and must be unique.</li>
|
||||||
|
<li>The <code>priority</code> block is optional (<span class="tip"><em>New!</em> in v2.9</span>):
|
||||||
|
<ul>
|
||||||
|
<li>Set the widget priority using any number; think of it like setting the css z-index.</li>
|
||||||
|
<li>This tells the plugin the order in which to run the widgets, lowest number priority first.</li>
|
||||||
|
<li>The default widgets have priorities set in intervals of 10 (see the <a href="index.html#Widget-options"> widget priority table</a>), so to run your custom widget before a specific widget, set your widget priority to less than that number.</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
<li>The <code>options</code> block (<span class="tip"><em>New!</em> in v2.8</span>):
|
<li>The <code>options</code> block (<span class="tip"><em>New!</em> in v2.8</span>):
|
||||||
<ul>
|
<ul>
|
||||||
<li>Include any widget options to be automatically be extended with any set widgetOptions (from <code>table.config.widgetOptions</code>).</li>
|
<li>Include any widget options to be automatically be extended with any set widgetOptions (from <code>table.config.widgetOptions</code>).</li>
|
||||||
@ -135,6 +142,8 @@
|
|||||||
// widgetOptions = all widget options (from table.config.widgetOptions)
|
// widgetOptions = all widget options (from table.config.widgetOptions)
|
||||||
$.tablesorter.addWidget({
|
$.tablesorter.addWidget({
|
||||||
id: 'myWidget',
|
id: 'myWidget',
|
||||||
|
// set the priority of the widget (optional)
|
||||||
|
priority: 10,
|
||||||
// widget options (added v2.8) - added to table.config.widgetOptions
|
// widget options (added v2.8) - added to table.config.widgetOptions
|
||||||
options: {
|
options: {
|
||||||
myWidget_option1 : 'setting1',
|
myWidget_option1 : 'setting1',
|
||||||
|
@ -1420,17 +1420,17 @@ $(function(){
|
|||||||
|
|
||||||
<table class="tablesorter compatibility">
|
<table class="tablesorter compatibility">
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th>Applied Order</th><th>Name</th><th>Requires jQuery</th><th>Limiting function</th></tr>
|
<tr><th>Widget Priority</th><th>Name</th><th>Requires jQuery</th><th>Limiting function</th></tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><td>6</td><td>columns</td><td>v1.2.6</td><td></td></tr>
|
<tr><td>60</td><td>columns</td><td>v1.2.6</td><td></td></tr>
|
||||||
<tr><td>5</td><td>filter</td><td>v1.4.3</td><td>1.4.3 (nextUntil)</td></tr>
|
<tr><td>50</td><td>filter</td><td>v1.4.3</td><td>1.4.3 (nextUntil)</td></tr>
|
||||||
<tr><td>8</td><td>pager</td><td>v1.2.6</td><td></td></tr>
|
<tr><td>Last</td><td>pager</td><td>v1.2.6</td><td></td></tr>
|
||||||
<tr><td>4</td><td>resizable</td><td>v1.4.1*</td><td>1.4 (isEmptyObject); 1.4.1 (parseJSON)*</td></tr>
|
<tr><td>40</td><td>resizable</td><td>v1.4.1*</td><td>1.4 (isEmptyObject); 1.4.1 (parseJSON)*</td></tr>
|
||||||
<tr><td>3</td><td>saveSort</td><td>v1.4.1</td><td>1.4.1 (parseJSON)*</td></tr>
|
<tr><td>30</td><td>saveSort</td><td>v1.4.1</td><td>1.4.1 (parseJSON)*</td></tr>
|
||||||
<tr><td>2</td><td>stickyHeaders</td><td>v1.2.6</td><td></td></tr>
|
<tr><td>20</td><td>stickyHeaders</td><td>v1.2.6</td><td></td></tr>
|
||||||
<tr><td>1</td><td>uitheme</td><td>v1.2.6</td><td></td></tr>
|
<tr><td>10</td><td>uitheme</td><td>v1.2.6</td><td></td></tr>
|
||||||
<tr><td>7</td><td>zebra</td><td>v1.2.6</td><td></td></tr>
|
<tr><td>90</td><td>zebra</td><td>v1.2.6</td><td></td></tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -1142,34 +1142,50 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
ts.applyWidget = function(table, init) {
|
ts.applyWidget = function(table, init) {
|
||||||
table = $(table)[0];
|
table = $(table)[0]; // in case this is called externally
|
||||||
var c = table.config,
|
var c = table.config,
|
||||||
wo = c.widgetOptions,
|
wo = c.widgetOptions,
|
||||||
ws = c.widgets.sort().reverse(), // ensure that widgets are always applied in a certain order
|
widgets = [],
|
||||||
time, i, w, l = ws.length;
|
time, i, w, wd;
|
||||||
// make zebra last
|
if (c.debug) { time = new Date(); }
|
||||||
i = $.inArray('zebra', c.widgets);
|
if (c.widgets.length) {
|
||||||
if (i >= 0) {
|
// ensure unique widget ids
|
||||||
c.widgets.splice(i,1);
|
c.widgets = $.grep(c.widgets, function(v, k){
|
||||||
c.widgets.push('zebra');
|
return $.inArray(v, c.widgets) === k;
|
||||||
|
});
|
||||||
|
// build widget array & add priority as needed
|
||||||
|
$.each(c.widgets || [], function(i,n){
|
||||||
|
wd = ts.getWidgetById(n);
|
||||||
|
if (wd && wd.id) {
|
||||||
|
// set priority to 10 if not defined
|
||||||
|
if (!wd.priority) { wd.priority = 10; }
|
||||||
|
widgets[i] = wd;
|
||||||
}
|
}
|
||||||
if (c.debug) {
|
});
|
||||||
time = new Date();
|
// sort widgets by priority
|
||||||
}
|
widgets.sort(function(a, b){
|
||||||
// add selected widgets
|
return a.priority < b.priority ? -1 : a.priority === b.priority ? 0 : 1;
|
||||||
for (i = 0; i < l; i++) {
|
});
|
||||||
w = ts.getWidgetById(ws[i]);
|
|
||||||
|
// add/update selected widgets
|
||||||
|
$.each(widgets, function(i,w){
|
||||||
if (w) {
|
if (w) {
|
||||||
if (init) {
|
if (init) {
|
||||||
if (w.hasOwnProperty('options')) { $.extend( true, w.options, wo ); }
|
if (w.hasOwnProperty('options')) {
|
||||||
if (w.hasOwnProperty('init')) { w.init(table, w, c, wo); }
|
wo = table.config.widgetOptions = $.extend( true, {}, w.options, wo );
|
||||||
|
}
|
||||||
|
if (w.hasOwnProperty('init')) {
|
||||||
|
w.init(table, w, c, wo);
|
||||||
|
}
|
||||||
} else if (!init && w.hasOwnProperty('format')) {
|
} else if (!init && w.hasOwnProperty('format')) {
|
||||||
w.format(table, c, wo, false);
|
w.format(table, c, wo, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (c.debug) {
|
if (c.debug) {
|
||||||
benchmark("Completed " + (init === true ? "initializing" : "applying") + " widgets", time);
|
w = c.widgets.length;
|
||||||
|
benchmark("Completed " + (init === true ? "initializing " : "applying ") + w + " widget" + (w !== 1 ? "s" : ""), time);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1409,6 +1425,7 @@
|
|||||||
// add default widgets
|
// add default widgets
|
||||||
ts.addWidget({
|
ts.addWidget({
|
||||||
id: "zebra",
|
id: "zebra",
|
||||||
|
priority: 90,
|
||||||
format: function(table, c, wo) {
|
format: function(table, c, wo) {
|
||||||
var $tb, $tv, $tr, row, even, time, k, l,
|
var $tb, $tv, $tr, row, even, time, k, l,
|
||||||
child = new RegExp(c.cssChildRow, 'i'),
|
child = new RegExp(c.cssChildRow, 'i'),
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
/*global jQuery: false, localStorage: false, navigator: false */
|
/*global jQuery: false, localStorage: false, navigator: false */
|
||||||
;(function($){
|
;(function($){
|
||||||
"use strict";
|
"use strict";
|
||||||
$.tablesorter = $.tablesorter || {};
|
var ts = $.tablesorter = $.tablesorter || {};
|
||||||
|
|
||||||
$.tablesorter.themes = {
|
ts.themes = {
|
||||||
"bootstrap" : {
|
"bootstrap" : {
|
||||||
table : 'table table-bordered table-striped',
|
table : 'table table-bordered table-striped',
|
||||||
header : 'bootstrap-header', // give the header a gradient background
|
header : 'bootstrap-header', // give the header a gradient background
|
||||||
@ -66,7 +66,7 @@ $.tablesorter.themes = {
|
|||||||
val = (v && v.hasOwnProperty('mywidget')) ? v.mywidget : '';
|
val = (v && v.hasOwnProperty('mywidget')) ? v.mywidget : '';
|
||||||
alert(val); // "data1" if saved, or "" if not
|
alert(val); // "data1" if saved, or "" if not
|
||||||
*/
|
*/
|
||||||
$.tablesorter.storage = function(table, key, val){
|
ts.storage = function(table, key, val){
|
||||||
var d, k, ls = false, v = {},
|
var d, k, ls = false, v = {},
|
||||||
id = table.id || $('.tablesorter').index( $(table) ),
|
id = table.id || $('.tablesorter').index( $(table) ),
|
||||||
url = window.location.pathname;
|
url = window.location.pathname;
|
||||||
@ -104,17 +104,19 @@ $.tablesorter.storage = function(table, key, val){
|
|||||||
// Widget: General UI theme
|
// Widget: General UI theme
|
||||||
// "uitheme" option in "widgetOptions"
|
// "uitheme" option in "widgetOptions"
|
||||||
// **************************
|
// **************************
|
||||||
$.tablesorter.addWidget({
|
ts.addWidget({
|
||||||
id: "uitheme",
|
id: "uitheme",
|
||||||
format: function(table){
|
priority: 10,
|
||||||
|
options: {
|
||||||
|
uitheme : 'jui'
|
||||||
|
},
|
||||||
|
format: function(table, c, wo){
|
||||||
var time, klass, $el, $tar,
|
var time, klass, $el, $tar,
|
||||||
t = $.tablesorter.themes,
|
t = ts.themes,
|
||||||
$t = $(table),
|
$t = c.$table,
|
||||||
c = table.config,
|
theme = c.theme !== 'default' ? c.theme : wo.uitheme || 'jui',
|
||||||
wo = c.widgetOptions,
|
|
||||||
theme = c.theme !== 'default' ? c.theme : wo.uitheme || 'jui', // default uitheme is 'jui'
|
|
||||||
o = t[ t[theme] ? theme : t[wo.uitheme] ? wo.uitheme : 'jui'],
|
o = t[ t[theme] ? theme : t[wo.uitheme] ? wo.uitheme : 'jui'],
|
||||||
$h = $(c.headerList),
|
$h = c.$headers,
|
||||||
sh = 'tr.' + (wo.stickyHeaders || 'tablesorter-stickyHeader'),
|
sh = 'tr.' + (wo.stickyHeaders || 'tablesorter-stickyHeader'),
|
||||||
rmv = o.sortNone + ' ' + o.sortDesc + ' ' + o.sortAsc;
|
rmv = o.sortNone + ' ' + o.sortDesc + ' ' + o.sortAsc;
|
||||||
if (c.debug) { time = new Date(); }
|
if (c.debug) { time = new Date(); }
|
||||||
@ -168,13 +170,13 @@ $.tablesorter.addWidget({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (c.debug){
|
if (c.debug){
|
||||||
$.tablesorter.benchmark("Applying " + theme + " theme", time);
|
ts.benchmark("Applying " + theme + " theme", time);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
remove: function(table, c, wo){
|
remove: function(table, c, wo){
|
||||||
var $t = $(table),
|
var $t = c.$table,
|
||||||
theme = typeof wo.uitheme === 'object' ? 'jui' : wo.uitheme || 'jui',
|
theme = typeof wo.uitheme === 'object' ? 'jui' : wo.uitheme || 'jui',
|
||||||
o = typeof wo.uitheme === 'object' ? wo.uitheme : $.tablesorter.themes[ $.tablesorter.themes.hasOwnProperty(theme) ? theme : 'jui'],
|
o = typeof wo.uitheme === 'object' ? wo.uitheme : ts.themes[ ts.themes.hasOwnProperty(theme) ? theme : 'jui'],
|
||||||
$h = $t.children('thead').children(),
|
$h = $t.children('thead').children(),
|
||||||
rmv = o.sortNone + ' ' + o.sortDesc + ' ' + o.sortAsc;
|
rmv = o.sortNone + ' ' + o.sortDesc + ' ' + o.sortAsc;
|
||||||
$t
|
$t
|
||||||
@ -192,17 +194,18 @@ $.tablesorter.addWidget({
|
|||||||
// "columns", "columns_thead" (true) and
|
// "columns", "columns_thead" (true) and
|
||||||
// "columns_tfoot" (true) options in "widgetOptions"
|
// "columns_tfoot" (true) options in "widgetOptions"
|
||||||
// **************************
|
// **************************
|
||||||
$.tablesorter.addWidget({
|
ts.addWidget({
|
||||||
id: "columns",
|
id: "columns",
|
||||||
format: function(table){
|
priority: 60,
|
||||||
|
options : {
|
||||||
|
columns : [ "primary", "secondary", "tertiary" ]
|
||||||
|
},
|
||||||
|
format: function(table, c, wo){
|
||||||
var $tb, $tr, $td, $t, time, last, rmv, i, k, l,
|
var $tb, $tr, $td, $t, time, last, rmv, i, k, l,
|
||||||
$tbl = $(table),
|
$tbl = c.$table,
|
||||||
c = table.config,
|
|
||||||
wo = c.widgetOptions,
|
|
||||||
b = c.$tbodies,
|
b = c.$tbodies,
|
||||||
list = c.sortList,
|
list = c.sortList,
|
||||||
len = list.length,
|
len = list.length,
|
||||||
css = [ "primary", "secondary", "tertiary" ]; // default options
|
|
||||||
// keep backwards compatibility, for now
|
// keep backwards compatibility, for now
|
||||||
css = (c.widgetColumns && c.widgetColumns.hasOwnProperty('css')) ? c.widgetColumns.css || css :
|
css = (c.widgetColumns && c.widgetColumns.hasOwnProperty('css')) ? c.widgetColumns.css || css :
|
||||||
(wo && wo.hasOwnProperty('columns')) ? wo.columns || css : css;
|
(wo && wo.hasOwnProperty('columns')) ? wo.columns || css : css;
|
||||||
@ -213,7 +216,7 @@ $.tablesorter.addWidget({
|
|||||||
}
|
}
|
||||||
// check if there is a sort (on initialization there may not be one)
|
// check if there is a sort (on initialization there may not be one)
|
||||||
for (k = 0; k < b.length; k++ ){
|
for (k = 0; k < b.length; k++ ){
|
||||||
$tb = $.tablesorter.processTbody(table, b.eq(k), true); // detach tbody
|
$tb = ts.processTbody(table, b.eq(k), true); // detach tbody
|
||||||
$tr = $tb.children('tr');
|
$tr = $tb.children('tr');
|
||||||
l = $tr.length;
|
l = $tr.length;
|
||||||
// loop through the visible rows
|
// loop through the visible rows
|
||||||
@ -235,7 +238,7 @@ $.tablesorter.addWidget({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$.tablesorter.processTbody(table, $tb, false);
|
ts.processTbody(table, $tb, false);
|
||||||
}
|
}
|
||||||
// add classes to thead and tfoot
|
// add classes to thead and tfoot
|
||||||
$tr = wo.columns_thead !== false ? 'thead tr' : '';
|
$tr = wo.columns_thead !== false ? 'thead tr' : '';
|
||||||
@ -256,7 +259,7 @@ $.tablesorter.addWidget({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c.debug){
|
if (c.debug){
|
||||||
$.tablesorter.benchmark("Applying Columns widget", time);
|
ts.benchmark("Applying Columns widget", time);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
remove: function(table, c, wo){
|
remove: function(table, c, wo){
|
||||||
@ -264,56 +267,55 @@ $.tablesorter.addWidget({
|
|||||||
b = c.$tbodies,
|
b = c.$tbodies,
|
||||||
rmv = (wo.columns || [ "primary", "secondary", "tertiary" ]).join(' ');
|
rmv = (wo.columns || [ "primary", "secondary", "tertiary" ]).join(' ');
|
||||||
c.$headers.removeClass(rmv);
|
c.$headers.removeClass(rmv);
|
||||||
$(table).children('tfoot').children('tr').children('th, td').removeClass(rmv);
|
c.$table.children('tfoot').children('tr').children('th, td').removeClass(rmv);
|
||||||
for (k = 0; k < b.length; k++ ){
|
for (k = 0; k < b.length; k++ ){
|
||||||
$tb = $.tablesorter.processTbody(table, b.eq(k), true); // remove tbody
|
$tb = ts.processTbody(table, b.eq(k), true); // remove tbody
|
||||||
$tb.children('tr').each(function(){
|
$tb.children('tr').each(function(){
|
||||||
$(this).children().removeClass(rmv);
|
$(this).children().removeClass(rmv);
|
||||||
});
|
});
|
||||||
$.tablesorter.processTbody(table, $tb, false); // restore tbody
|
ts.processTbody(table, $tb, false); // restore tbody
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Widget: filter
|
// Widget: filter
|
||||||
widgetOptions:
|
// **************************
|
||||||
filter_childRows : false // if true, filter includes child row content in the search
|
ts.addWidget({
|
||||||
filter_columnFilters : true // if true, a filter will be added to the top of each table column
|
|
||||||
filter_cssFilter : 'tablesorter-filter' // css class name added to the filter row & each input in the row
|
|
||||||
filter_formatter : null // add custom filter elements to the filter row
|
|
||||||
filter_functions : null // add custom filter functions using this option
|
|
||||||
filter_hideFilters : false // collapse filter row when mouse leaves the area
|
|
||||||
filter_ignoreCase : true // if true, make all searches case-insensitive
|
|
||||||
filter_reset : null // jQuery selector string of an element used to reset the filters
|
|
||||||
filter_searchDelay : 300 // typing delay in milliseconds before starting a search
|
|
||||||
filter_startsWith : false // if true, filter start from the beginning of the cell contents
|
|
||||||
filter_useParsedData : false // filter all data using parsed content
|
|
||||||
filter_serversideFiltering : false // if true, server-side filtering should be performed because client-side filtering will be disabled, but the ui and events will still be used.
|
|
||||||
**************************/
|
|
||||||
$.tablesorter.addWidget({
|
|
||||||
id: "filter",
|
id: "filter",
|
||||||
format: function(table){
|
priority: 50,
|
||||||
if (table.config.parsers && !$(table).hasClass('hasFilters')){
|
options : {
|
||||||
var i, j, k, l, val, ff, x, xi, st, sel, str,
|
filter_childRows : false, // if true, filter includes child row content in the search
|
||||||
ft, ft2, $th, $fr, rg, s, t, dis, col,
|
filter_columnFilters : true, // if true, a filter will be added to the top of each table column
|
||||||
fmt = $.tablesorter.formatFloat,
|
filter_cssFilter : 'tablesorter-filter', // css class name added to the filter row & each input in the row
|
||||||
last = '', // save last filter search
|
filter_formatter : null, // add custom filter elements to the filter row
|
||||||
ts = $.tablesorter,
|
filter_functions : null, // add custom filter functions using this option
|
||||||
c = table.config,
|
filter_hideFilters : false, // collapse filter row when mouse leaves the area
|
||||||
$ths = $(c.headerList),
|
filter_ignoreCase : true, // if true, make all searches case-insensitive
|
||||||
wo = c.widgetOptions,
|
filter_reset : null, // jQuery selector string of an element used to reset the filters
|
||||||
css = wo.filter_cssFilter || 'tablesorter-filter',
|
filter_searchDelay : 300, // typing delay in milliseconds before starting a search
|
||||||
$t = $(table).addClass('hasFilters'),
|
filter_startsWith : false, // if true, filter start from the beginning of the cell contents
|
||||||
b = $t.find('tbody'),
|
filter_useParsedData : false, // filter all data using parsed content
|
||||||
cols = c.parsers.length,
|
filter_serversideFiltering : false, // if true, server-side filtering should be performed because client-side filtering will be disabled, but the ui and events will still be used.
|
||||||
reg = { // regex used in filter "check" functions
|
filter_regex : { // regex used in filter "check" functions
|
||||||
"regex" : /^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/, // regex to test for regex
|
"regex" : /^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/, // regex to test for regex
|
||||||
"child" : new RegExp(c.cssChildRow), // child row
|
"child" : /tablesorter-childRow/, // child row class name; this gets updated in the script
|
||||||
"type" : /undefined|number/, // check type
|
"type" : /undefined|number/, // check type
|
||||||
"exact" : /(^[\"|\'|=])|([\"|\'|=]$)/g, // exact match
|
"exact" : /(^[\"|\'|=])|([\"|\'|=]$)/g, // exact match
|
||||||
"nondigit" : /[^\w,. \-()]/g, // replace non-digits (from digit & currency parser)
|
"nondigit" : /[^\w,. \-()]/g, // replace non-digits (from digit & currency parser)
|
||||||
"operators" : /[<>=]/g // replace operators
|
"operators" : /[<>=]/g // replace operators
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
format: function(table, c, wo){
|
||||||
|
if (c.parsers && !c.$table.hasClass('hasFilters')){
|
||||||
|
var i, j, k, l, val, ff, x, xi, st, sel, str,
|
||||||
|
ft, ft2, $th, $fr, rg, s, t, dis, col,
|
||||||
|
fmt = ts.formatFloat,
|
||||||
|
last = '', // save last filter search
|
||||||
|
$ths = c.$headers,
|
||||||
|
css = wo.filter_cssFilter || 'tablesorter-filter',
|
||||||
|
$t = c.$table.addClass('hasFilters'),
|
||||||
|
b = $t.find('tbody'),
|
||||||
|
cols = c.parsers.length,
|
||||||
parsed, time, timer,
|
parsed, time, timer,
|
||||||
|
|
||||||
// dig fer gold
|
// dig fer gold
|
||||||
@ -332,7 +334,7 @@ $.tablesorter.addWidget({
|
|||||||
$(el).val(filter[i] || '');
|
$(el).val(filter[i] || '');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (wo.filter_hideFilters === true){
|
if (wo.filter_hideFilters){
|
||||||
// show/hide filter row as needed
|
// show/hide filter row as needed
|
||||||
$t.find('.tablesorter-filter-row').trigger( cv === '' ? 'mouseleave' : 'mouseenter' );
|
$t.find('.tablesorter-filter-row').trigger( cv === '' ? 'mouseleave' : 'mouseenter' );
|
||||||
}
|
}
|
||||||
@ -357,7 +359,7 @@ $.tablesorter.addWidget({
|
|||||||
|
|
||||||
for (k = 0; k < b.length; k++ ){
|
for (k = 0; k < b.length; k++ ){
|
||||||
if (b.eq(k).hasClass(c.cssInfoBlock)) { continue; } // ignore info blocks, issue #264
|
if (b.eq(k).hasClass(c.cssInfoBlock)) { continue; } // ignore info blocks, issue #264
|
||||||
$tb = $.tablesorter.processTbody(table, b.eq(k), true);
|
$tb = ts.processTbody(table, b.eq(k), true);
|
||||||
$tr = $tb.children('tr');
|
$tr = $tb.children('tr');
|
||||||
l = $tr.length;
|
l = $tr.length;
|
||||||
if (cv === '' || wo.filter_serversideFiltering){
|
if (cv === '' || wo.filter_serversideFiltering){
|
||||||
@ -366,14 +368,13 @@ $.tablesorter.addWidget({
|
|||||||
// loop through the rows
|
// loop through the rows
|
||||||
for (j = 0; j < l; j++){
|
for (j = 0; j < l; j++){
|
||||||
// skip child rows
|
// skip child rows
|
||||||
if (reg.child.test($tr[j].className)) { continue; }
|
if (wo.filter_regex.child.test($tr[j].className)) { continue; }
|
||||||
r = true;
|
r = true;
|
||||||
cr = $tr.eq(j).nextUntil('tr:not(.' + c.cssChildRow + ')');
|
cr = $tr.eq(j).nextUntil('tr:not(.' + c.cssChildRow + ')');
|
||||||
// so, if "table.config.widgetOptions.filter_childRows" is true and there is
|
// so, if "table.config.widgetOptions.filter_childRows" is true and there is
|
||||||
// a match anywhere in the child row, then it will make the row visible
|
// a match anywhere in the child row, then it will make the row visible
|
||||||
// checked here so the option can be changed dynamically
|
// checked here so the option can be changed dynamically
|
||||||
t = (cr.length && (wo && wo.hasOwnProperty('filter_childRows') &&
|
t = (cr.length && wo.filter_childRows) ? cr.text() : '';
|
||||||
typeof wo.filter_childRows !== 'undefined' ? wo.filter_childRows : true)) ? cr.text() : '';
|
|
||||||
t = wo.filter_ignoreCase ? t.toLocaleLowerCase() : t;
|
t = wo.filter_ignoreCase ? t.toLocaleLowerCase() : t;
|
||||||
$td = $tr.eq(j).children('td');
|
$td = $tr.eq(j).children('td');
|
||||||
for (i = 0; i < cols; i++){
|
for (i = 0; i < cols; i++){
|
||||||
@ -386,7 +387,7 @@ $.tablesorter.addWidget({
|
|||||||
// using older or original tablesorter
|
// using older or original tablesorter
|
||||||
x = $.trim($td.eq(i).text());
|
x = $.trim($td.eq(i).text());
|
||||||
}
|
}
|
||||||
xi = !reg.type.test(typeof x) && wo.filter_ignoreCase ? x.toLocaleLowerCase() : x;
|
xi = !wo.filter_regex.type.test(typeof x) && wo.filter_ignoreCase ? x.toLocaleLowerCase() : x;
|
||||||
ff = r; // if r is true, show that row
|
ff = r; // if r is true, show that row
|
||||||
// val = case insensitive, v[i] = case sensitive
|
// val = case insensitive, v[i] = case sensitive
|
||||||
val = wo.filter_ignoreCase ? v[i].toLocaleLowerCase() : v[i];
|
val = wo.filter_ignoreCase ? v[i].toLocaleLowerCase() : v[i];
|
||||||
@ -402,8 +403,8 @@ $.tablesorter.addWidget({
|
|||||||
ff = wo.filter_functions[i][v[i]](x, c.cache[k].normalized[j][i], v[i], i);
|
ff = wo.filter_functions[i][v[i]](x, c.cache[k].normalized[j][i], v[i], i);
|
||||||
}
|
}
|
||||||
// Look for regex
|
// Look for regex
|
||||||
} else if (reg.regex.test(val)){
|
} else if (wo.filter_regex.regex.test(val)){
|
||||||
rg = reg.regex.exec(val);
|
rg = wo.filter_regex.regex.exec(val);
|
||||||
try {
|
try {
|
||||||
ff = new RegExp(rg[1], rg[2]).test(xi);
|
ff = new RegExp(rg[1], rg[2]).test(xi);
|
||||||
} catch (err){
|
} catch (err){
|
||||||
@ -411,7 +412,7 @@ $.tablesorter.addWidget({
|
|||||||
}
|
}
|
||||||
// Look for quotes or equals to get an exact match; ignore type since xi could be numeric
|
// Look for quotes or equals to get an exact match; ignore type since xi could be numeric
|
||||||
/*jshint eqeqeq:false */
|
/*jshint eqeqeq:false */
|
||||||
} else if (val.replace(reg.exact, '') == xi){
|
} else if (val.replace(wo.filter_regex.exact, '') == xi){
|
||||||
ff = true;
|
ff = true;
|
||||||
// Look for a not match
|
// Look for a not match
|
||||||
} else if (/^\!/.test(val)){
|
} else if (/^\!/.test(val)){
|
||||||
@ -421,8 +422,8 @@ $.tablesorter.addWidget({
|
|||||||
// Look for operators >, >=, < or <=
|
// Look for operators >, >=, < or <=
|
||||||
} else if (/^[<>]=?/.test(val)){
|
} else if (/^[<>]=?/.test(val)){
|
||||||
// xi may be numeric - see issue #149
|
// xi may be numeric - see issue #149
|
||||||
rg = isNaN(xi) ? fmt(xi.replace(reg.nondigit, ''), table) : fmt(xi, table);
|
rg = isNaN(xi) ? fmt(xi.replace(wo.filter_regex.nondigit, ''), table) : fmt(xi, table);
|
||||||
s = fmt(val.replace(reg.nondigit, '').replace(reg.operators,''), table);
|
s = fmt(val.replace(wo.filter_regex.nondigit, '').replace(wo.filter_regex.operators,''), table);
|
||||||
if (/>/.test(val)) { ff = />=/.test(val) ? rg >= s : rg > s; }
|
if (/>/.test(val)) { ff = />=/.test(val) ? rg >= s : rg > s; }
|
||||||
if (/</.test(val)) { ff = /<=/.test(val) ? rg <= s : rg < s; }
|
if (/</.test(val)) { ff = /<=/.test(val) ? rg <= s : rg < s; }
|
||||||
if (s === '') { ff = true; } // keep showing all rows if nothing follows the operator
|
if (s === '') { ff = true; } // keep showing all rows if nothing follows the operator
|
||||||
@ -437,10 +438,10 @@ $.tablesorter.addWidget({
|
|||||||
}
|
}
|
||||||
// Look for a range (using " to " or " - ") - see issue #166; thanks matzhu!
|
// Look for a range (using " to " or " - ") - see issue #166; thanks matzhu!
|
||||||
} else if (/\s+(-|to)\s+/.test(val)){
|
} else if (/\s+(-|to)\s+/.test(val)){
|
||||||
rg = isNaN(xi) ? fmt(xi.replace(reg.nondigit, ''), table) : fmt(xi, table);
|
rg = isNaN(xi) ? fmt(xi.replace(wo.filter_regex.nondigit, ''), table) : fmt(xi, table);
|
||||||
s = val.split(/(?: - | to )/); // make sure the dash is for a range and not indicating a negative number
|
s = val.split(/(?: - | to )/); // make sure the dash is for a range and not indicating a negative number
|
||||||
r1 = fmt(s[0].replace(reg.nondigit, ''), table);
|
r1 = fmt(s[0].replace(wo.filter_regex.nondigit, ''), table);
|
||||||
r2 = fmt(s[1].replace(reg.nondigit, ''), table);
|
r2 = fmt(s[1].replace(wo.filter_regex.nondigit, ''), table);
|
||||||
if (r1 > r2) { ff = r1; r1 = r2; r2 = ff; } // swap
|
if (r1 > r2) { ff = r1; r1 = r2; r2 = ff; } // swap
|
||||||
ff = (rg >= r1 && rg <= r2) || (r1 === '' || r2 === '') ? true : false;
|
ff = (rg >= r1 && rg <= r2) || (r1 === '' || r2 === '') ? true : false;
|
||||||
// Look for wild card: ? = single, * = multiple, or | = logical OR
|
// Look for wild card: ? = single, * = multiple, or | = logical OR
|
||||||
@ -459,7 +460,7 @@ $.tablesorter.addWidget({
|
|||||||
if (cr.length) { cr[r ? 'show' : 'hide'](); }
|
if (cr.length) { cr[r ? 'show' : 'hide'](); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$.tablesorter.processTbody(table, $tb, false);
|
ts.processTbody(table, $tb, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
last = cv; // save last search
|
last = cv; // save last search
|
||||||
@ -520,8 +521,7 @@ $.tablesorter.addWidget({
|
|||||||
if (c.debug){
|
if (c.debug){
|
||||||
time = new Date();
|
time = new Date();
|
||||||
}
|
}
|
||||||
wo.filter_ignoreCase = wo.filter_ignoreCase !== false; // set default filter_ignoreCase to true
|
wo.filter_regex.child = new RegExp(c.cssChildRow);
|
||||||
wo.filter_useParsedData = wo.filter_useParsedData === true; // default is false
|
|
||||||
// don't build filter row if columnFilters is false or all columns are set to "filter-false" - issue #156
|
// don't build filter row if columnFilters is false or all columns are set to "filter-false" - issue #156
|
||||||
if (wo.filter_columnFilters !== false && $ths.filter('.filter-false').length !== $ths.length){
|
if (wo.filter_columnFilters !== false && $ths.filter('.filter-false').length !== $ths.length){
|
||||||
// build filter row
|
// build filter row
|
||||||
@ -595,7 +595,7 @@ $.tablesorter.addWidget({
|
|||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
timer = setTimeout(function(){
|
timer = setTimeout(function(){
|
||||||
checkFilters(false);
|
checkFilters(false);
|
||||||
}, wo.filter_searchDelay || 300);
|
}, wo.filter_searchDelay);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -639,7 +639,7 @@ $.tablesorter.addWidget({
|
|||||||
checkFilters();
|
checkFilters();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (wo.filter_hideFilters === true){
|
if (wo.filter_hideFilters){
|
||||||
$t
|
$t
|
||||||
.find('.tablesorter-filter-row')
|
.find('.tablesorter-filter-row')
|
||||||
.addClass('hideme')
|
.addClass('hideme')
|
||||||
@ -656,7 +656,7 @@ $.tablesorter.addWidget({
|
|||||||
// $(':focus') needs jQuery 1.6+
|
// $(':focus') needs jQuery 1.6+
|
||||||
if ($(document.activeElement).closest('tr')[0] !== ft[0]){
|
if ($(document.activeElement).closest('tr')[0] !== ft[0]){
|
||||||
// get all filter values
|
// get all filter values
|
||||||
all = $t.find('.' + (wo.filter_cssFilter || 'tablesorter-filter')).map(function(){
|
all = $t.find('.' + wo.filter_cssFilter).map(function(){
|
||||||
return $(this).val() || '';
|
return $(this).val() || '';
|
||||||
}).get().join('');
|
}).get().join('');
|
||||||
// don't hide row if any filter has a value
|
// don't hide row if any filter has a value
|
||||||
@ -672,7 +672,7 @@ $.tablesorter.addWidget({
|
|||||||
clearTimeout(st);
|
clearTimeout(st);
|
||||||
st = setTimeout(function(){
|
st = setTimeout(function(){
|
||||||
// don't hide row if any filter has a value
|
// don't hide row if any filter has a value
|
||||||
if ($t.find('.' + (wo.filter_cssFilter || 'tablesorter-filter')).map(function(){ return $(this).val() || ''; }).get().join('') === ''){
|
if ($t.find('.' + wo.filter_cssFilter).map(function(){ return $(this).val() || ''; }).get().join('') === ''){
|
||||||
ft2[ e.type === 'focus' ? 'removeClass' : 'addClass']('hideme');
|
ft2[ e.type === 'focus' ? 'removeClass' : 'addClass']('hideme');
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
@ -699,7 +699,7 @@ $.tablesorter.addWidget({
|
|||||||
},
|
},
|
||||||
remove: function(table, c, wo){
|
remove: function(table, c, wo){
|
||||||
var k, $tb,
|
var k, $tb,
|
||||||
$t = $(table),
|
$t = c.$table,
|
||||||
b = c.$tbodies;
|
b = c.$tbodies;
|
||||||
$t
|
$t
|
||||||
.removeClass('hasFilters')
|
.removeClass('hasFilters')
|
||||||
@ -707,9 +707,9 @@ $.tablesorter.addWidget({
|
|||||||
.unbind('addRows updateCell update updateComplete appendCache search filterStart filterEnd '.split(' ').join('.tsfilter '))
|
.unbind('addRows updateCell update updateComplete appendCache search filterStart filterEnd '.split(' ').join('.tsfilter '))
|
||||||
.find('.tablesorter-filter-row').remove();
|
.find('.tablesorter-filter-row').remove();
|
||||||
for (k = 0; k < b.length; k++ ){
|
for (k = 0; k < b.length; k++ ){
|
||||||
$tb = $.tablesorter.processTbody(table, b.eq(k), true); // remove tbody
|
$tb = ts.processTbody(table, b.eq(k), true); // remove tbody
|
||||||
$tb.children().removeClass('filtered').show();
|
$tb.children().removeClass('filtered').show();
|
||||||
$.tablesorter.processTbody(table, $tb, false); // restore tbody
|
ts.processTbody(table, $tb, false); // restore tbody
|
||||||
}
|
}
|
||||||
if (wo.filterreset) { $(wo.filter_reset).unbind('click.tsfilter'); }
|
if (wo.filterreset) { $(wo.filter_reset).unbind('click.tsfilter'); }
|
||||||
}
|
}
|
||||||
@ -720,24 +720,26 @@ $.tablesorter.addWidget({
|
|||||||
// http://css-tricks.com/13465-persistent-headers/
|
// http://css-tricks.com/13465-persistent-headers/
|
||||||
// and https://github.com/jmosbech/StickyTableHeaders by Jonas Mosbech
|
// and https://github.com/jmosbech/StickyTableHeaders by Jonas Mosbech
|
||||||
// **************************
|
// **************************
|
||||||
$.tablesorter.addWidget({
|
ts.addWidget({
|
||||||
id: "stickyHeaders",
|
id: "stickyHeaders",
|
||||||
format: function(table){
|
priority: 20,
|
||||||
if ($(table).hasClass('hasStickyHeaders')) { return; }
|
options: {
|
||||||
var $table = $(table).addClass('hasStickyHeaders'),
|
stickyHeaders: 'tablesorter-stickyHeader',
|
||||||
c = table.config,
|
stickyHeaders_cloneId: '-sticky', // added to table ID, if it exists
|
||||||
wo = c.widgetOptions,
|
},
|
||||||
|
format: function(table, c, wo){
|
||||||
|
if (c.$table.hasClass('hasStickyHeaders')) { return; }
|
||||||
|
var $table = c.$table.addClass('hasStickyHeaders'),
|
||||||
win = $(window),
|
win = $(window),
|
||||||
header = $(table).children('thead:first'), //.add( $(table).find('caption') ),
|
header = c.$table.children('thead:first'), //.add( c.$table.find('caption') ),
|
||||||
hdrCells = header.children('tr:not(.sticky-false)').children(),
|
hdrCells = header.children('tr:not(.sticky-false)').children(),
|
||||||
css = wo.stickyHeaders || 'tablesorter-stickyHeader',
|
|
||||||
innr = '.tablesorter-header-inner',
|
innr = '.tablesorter-header-inner',
|
||||||
firstRow = hdrCells.eq(0).parent(),
|
firstRow = hdrCells.eq(0).parent(),
|
||||||
tfoot = $table.find('tfoot'),
|
tfoot = $table.find('tfoot'),
|
||||||
t2 = wo.$sticky = $table.clone(), // clone table, but don't remove id... the table might be styled by css
|
t2 = wo.$sticky = $table.clone(),
|
||||||
// clone the entire thead - seems to work in IE8+
|
// clone the entire thead - seems to work in IE8+
|
||||||
stkyHdr = t2.children('thead:first')
|
stkyHdr = t2.children('thead:first')
|
||||||
.addClass(css)
|
.addClass(wo.stickyHeaders)
|
||||||
.css({
|
.css({
|
||||||
width : header.outerWidth(true),
|
width : header.outerWidth(true),
|
||||||
position : 'fixed',
|
position : 'fixed',
|
||||||
@ -777,6 +779,8 @@ $.tablesorter.addWidget({
|
|||||||
$(this).width(w);
|
$(this).width(w);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
// fix clone ID, if it exists - fixes #271
|
||||||
|
if (t2.attr('id')) { t2[0].id += wo.stickyHeaders_cloneId; }
|
||||||
// clear out cloned table, except for sticky header
|
// clear out cloned table, except for sticky header
|
||||||
t2.find('thead:gt(0), tr.sticky-false, tbody, tfoot, caption').remove();
|
t2.find('thead:gt(0), tr.sticky-false, tbody, tfoot, caption').remove();
|
||||||
t2.css({ height:0, width:0, padding:0, margin:0, border:0 });
|
t2.css({ height:0, width:0, padding:0, margin:0, border:0 });
|
||||||
@ -823,8 +827,7 @@ $.tablesorter.addWidget({
|
|||||||
sTop = win.scrollTop(),
|
sTop = win.scrollTop(),
|
||||||
tableHt = $table.height() - (stkyHdr.height() + (tfoot.height() || 0)),
|
tableHt = $table.height() - (stkyHdr.height() + (tfoot.height() || 0)),
|
||||||
vis = (sTop > offset.top) && (sTop < offset.top + tableHt) ? 'visible' : 'hidden';
|
vis = (sTop > offset.top) && (sTop < offset.top + tableHt) ? 'visible' : 'hidden';
|
||||||
stkyHdr
|
stkyHdr.css({
|
||||||
.css({
|
|
||||||
// adjust when scrolling horizontally - fixes issue #143
|
// adjust when scrolling horizontally - fixes issue #143
|
||||||
left : header.offset().left - win.scrollLeft() - spacing,
|
left : header.offset().left - win.scrollLeft() - spacing,
|
||||||
visibility : vis
|
visibility : vis
|
||||||
@ -840,12 +843,10 @@ $.tablesorter.addWidget({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
remove: function(table, c, wo){
|
remove: function(table, c, wo){
|
||||||
var $t = $(table),
|
c.$table
|
||||||
css = wo.stickyHeaders || 'tablesorter-stickyHeader';
|
|
||||||
$t
|
|
||||||
.removeClass('hasStickyHeaders')
|
.removeClass('hasStickyHeaders')
|
||||||
.unbind('sortEnd.tsSticky pagerComplete.tsSticky')
|
.unbind('sortEnd.tsSticky pagerComplete.tsSticky')
|
||||||
.find('.' + css).remove();
|
.find('.' + wo.stickyHeaders).remove();
|
||||||
if (wo.$sticky) { wo.$sticky.remove(); } // remove cloned thead
|
if (wo.$sticky) { wo.$sticky.remove(); } // remove cloned thead
|
||||||
$(window).unbind('scroll.tsSticky resize.tsSticky');
|
$(window).unbind('scroll.tsSticky resize.tsSticky');
|
||||||
}
|
}
|
||||||
@ -855,39 +856,42 @@ $.tablesorter.addWidget({
|
|||||||
// this widget saves the column widths if
|
// this widget saves the column widths if
|
||||||
// $.tablesorter.storage function is included
|
// $.tablesorter.storage function is included
|
||||||
// **************************
|
// **************************
|
||||||
$.tablesorter.addWidget({
|
ts.addWidget({
|
||||||
id: "resizable",
|
id: "resizable",
|
||||||
format: function(table){
|
priority: 40,
|
||||||
if ($(table).hasClass('hasResizable')) { return; }
|
options: {
|
||||||
$(table).addClass('hasResizable');
|
resizable : true,
|
||||||
var $t, t, i, j, s, $c, $cols, w, tw,
|
resizable_addLastColumn : false
|
||||||
$tbl = $(table),
|
},
|
||||||
c = table.config,
|
format: function(table, c, wo){
|
||||||
wo = c.widgetOptions,
|
if (c.$table.hasClass('hasResizable')) { return; }
|
||||||
|
c.$table.addClass('hasResizable');
|
||||||
|
var $t, t, i, j, s = {}, $c, $cols, w, tw,
|
||||||
|
$tbl = c.$table,
|
||||||
position = 0,
|
position = 0,
|
||||||
$target = null,
|
$target = null,
|
||||||
$next = null,
|
$next = null,
|
||||||
fullWidth = Math.abs($tbl.parent().width() - $tbl.width()) < 20,
|
fullWidth = Math.abs($tbl.parent().width() - $tbl.width()) < 20,
|
||||||
stopResize = function(){
|
stopResize = function(){
|
||||||
if ($.tablesorter.storage && $target){
|
if (ts.storage && $target){
|
||||||
s[$target.index()] = $target.width();
|
s[$target.index()] = $target.width();
|
||||||
s[$next.index()] = $next.width();
|
s[$next.index()] = $next.width();
|
||||||
$target.width( s[$target.index()] );
|
$target.width( s[$target.index()] );
|
||||||
$next.width( s[$next.index()] );
|
$next.width( s[$next.index()] );
|
||||||
if (wo.resizable !== false){
|
if (wo.resizable !== false){
|
||||||
$.tablesorter.storage(table, 'tablesorter-resizable', s);
|
ts.storage(table, 'tablesorter-resizable', s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
position = 0;
|
position = 0;
|
||||||
$target = $next = null;
|
$target = $next = null;
|
||||||
$(window).trigger('resize'); // will update stickyHeaders, just in case
|
$(window).trigger('resize'); // will update stickyHeaders, just in case
|
||||||
};
|
};
|
||||||
s = ($.tablesorter.storage && wo.resizable !== false) ? $.tablesorter.storage(table, 'tablesorter-resizable') : {};
|
s = (ts.storage && wo.resizable !== false) ? ts.storage(table, 'tablesorter-resizable') : {};
|
||||||
// process only if table ID or url match
|
// process only if table ID or url match
|
||||||
if (s){
|
if (s){
|
||||||
for (j in s){
|
for (j in s){
|
||||||
if (!isNaN(j) && j < c.headerList.length){
|
if (!isNaN(j) && j < c.$headers.length){
|
||||||
$(c.headerList[j]).width(s[j]); // set saved resizable widths
|
c.$headers.eq(j).width(s[j]); // set saved resizable widths
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -896,7 +900,7 @@ $.tablesorter.addWidget({
|
|||||||
$t.children().each(function(){
|
$t.children().each(function(){
|
||||||
t = $(this);
|
t = $(this);
|
||||||
i = t.attr('data-column');
|
i = t.attr('data-column');
|
||||||
j = $.tablesorter.getData( t, c.headers[i], 'resizable') === "false";
|
j = ts.getData( t, c.headers[i], 'resizable') === "false";
|
||||||
$t.children().filter('[data-column="' + i + '"]').toggleClass('resizable-false', j);
|
$t.children().filter('[data-column="' + i + '"]').toggleClass('resizable-false', j);
|
||||||
});
|
});
|
||||||
// add wrapper inside each cell to allow for positioning of the resizable target block
|
// add wrapper inside each cell to allow for positioning of the resizable target block
|
||||||
@ -951,15 +955,15 @@ $.tablesorter.addWidget({
|
|||||||
})
|
})
|
||||||
// right click to reset columns to default widths
|
// right click to reset columns to default widths
|
||||||
.bind('contextmenu.tsresize', function(){
|
.bind('contextmenu.tsresize', function(){
|
||||||
$.tablesorter.resizableReset(table);
|
ts.resizableReset(table);
|
||||||
// $.isEmptyObject() needs jQuery 1.4+
|
// $.isEmptyObject() needs jQuery 1.4+
|
||||||
var rtn = $.isEmptyObject ? $.isEmptyObject(s) : s === {}; // allow right click if already reset
|
var rtn = $.isEmptyObject ? $.isEmptyObject(s) : s === {}; // allow right click if already reset
|
||||||
s = {};
|
s = {};
|
||||||
return rtn;
|
return rtn;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
remove: function(table){
|
remove: function(table, c, wo){
|
||||||
$(table)
|
c.$table
|
||||||
.removeClass('hasResizable')
|
.removeClass('hasResizable')
|
||||||
.find('thead')
|
.find('thead')
|
||||||
.unbind('mouseup.tsresize mouseleave.tsresize contextmenu.tsresize')
|
.unbind('mouseup.tsresize mouseleave.tsresize contextmenu.tsresize')
|
||||||
@ -967,12 +971,12 @@ $.tablesorter.addWidget({
|
|||||||
.unbind('mousemove.tsresize mouseup.tsresize')
|
.unbind('mousemove.tsresize mouseup.tsresize')
|
||||||
// don't remove "tablesorter-wrapper" as uitheme uses it too
|
// don't remove "tablesorter-wrapper" as uitheme uses it too
|
||||||
.find('.tablesorter-resizer,.tablesorter-resizer-grip').remove();
|
.find('.tablesorter-resizer,.tablesorter-resizer-grip').remove();
|
||||||
$.tablesorter.resizableReset(table);
|
ts.resizableReset(table);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$.tablesorter.resizableReset = function(table){
|
ts.resizableReset = function(table){
|
||||||
$(table.config.headerList).filter(':not(.resizable-false)').css('width','');
|
table.config.$headers.filter(':not(.resizable-false)').css('width','');
|
||||||
if ($.tablesorter.storage) { $.tablesorter.storage(table, 'tablesorter-resizable', {}); }
|
if (ts.storage) { ts.storage(table, 'tablesorter-resizable', {}); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save table sort widget
|
// Save table sort widget
|
||||||
@ -980,27 +984,29 @@ $.tablesorter.resizableReset = function(table){
|
|||||||
// saveSort widget option is true AND the
|
// saveSort widget option is true AND the
|
||||||
// $.tablesorter.storage function is included
|
// $.tablesorter.storage function is included
|
||||||
// **************************
|
// **************************
|
||||||
$.tablesorter.addWidget({
|
ts.addWidget({
|
||||||
id: 'saveSort',
|
id: 'saveSort',
|
||||||
|
priority: 30,
|
||||||
|
options: {
|
||||||
|
saveSort : true
|
||||||
|
},
|
||||||
init: function(table, thisWidget, c, wo){
|
init: function(table, thisWidget, c, wo){
|
||||||
// run widget format before all other widgets are applied to the table
|
// run widget format before all other widgets are applied to the table
|
||||||
thisWidget.format(table, c, wo, true);
|
thisWidget.format(table, c, wo, true);
|
||||||
},
|
},
|
||||||
format: function(table, c, wo, init){
|
format: function(table, c, wo, init){
|
||||||
// redefining c & wo for backwards compatibility
|
var sl, time,
|
||||||
c = table.config;
|
$t = c.$table,
|
||||||
wo = c.widgetOptions;
|
|
||||||
var sl, time, $t = $(table),
|
|
||||||
ss = wo.saveSort !== false, // make saveSort active/inactive; default to true
|
ss = wo.saveSort !== false, // make saveSort active/inactive; default to true
|
||||||
sortList = { "sortList" : c.sortList };
|
sortList = { "sortList" : c.sortList };
|
||||||
if (c.debug){
|
if (c.debug){
|
||||||
time = new Date();
|
time = new Date();
|
||||||
}
|
}
|
||||||
if ($t.hasClass('hasSaveSort')){
|
if ($t.hasClass('hasSaveSort')){
|
||||||
if (ss && table.hasInitialized && $.tablesorter.storage){
|
if (ss && table.hasInitialized && ts.storage){
|
||||||
$.tablesorter.storage( table, 'tablesorter-savesort', sortList );
|
ts.storage( table, 'tablesorter-savesort', sortList );
|
||||||
if (c.debug){
|
if (c.debug){
|
||||||
$.tablesorter.benchmark('saveSort widget: Saving last sort: ' + c.sortList, time);
|
ts.benchmark('saveSort widget: Saving last sort: ' + c.sortList, time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1008,15 +1014,15 @@ $.tablesorter.addWidget({
|
|||||||
$t.addClass('hasSaveSort');
|
$t.addClass('hasSaveSort');
|
||||||
sortList = '';
|
sortList = '';
|
||||||
// get data
|
// get data
|
||||||
if ($.tablesorter.storage){
|
if (ts.storage){
|
||||||
sl = $.tablesorter.storage( table, 'tablesorter-savesort' );
|
sl = ts.storage( table, 'tablesorter-savesort' );
|
||||||
sortList = (sl && sl.hasOwnProperty('sortList') && $.isArray(sl.sortList)) ? sl.sortList : '';
|
sortList = (sl && sl.hasOwnProperty('sortList') && $.isArray(sl.sortList)) ? sl.sortList : '';
|
||||||
if (c.debug){
|
if (c.debug){
|
||||||
$.tablesorter.benchmark('saveSort: Last sort loaded: "' + sortList + '"', time);
|
ts.benchmark('saveSort: Last sort loaded: "' + sortList + '"', time);
|
||||||
}
|
}
|
||||||
$t.bind('saveSortReset', function(e){
|
$t.bind('saveSortReset', function(e){
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
$.tablesorter.storage( table, 'tablesorter-savesort', '' );
|
ts.storage( table, 'tablesorter-savesort', '' );
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// init is true when widget init is run, this will run this widget before all other widgets have initialized
|
// init is true when widget init is run, this will run this widget before all other widgets have initialized
|
||||||
@ -1031,7 +1037,7 @@ $.tablesorter.addWidget({
|
|||||||
},
|
},
|
||||||
remove: function(table){
|
remove: function(table){
|
||||||
// clear storage
|
// clear storage
|
||||||
if ($.tablesorter.storage) { $.tablesorter.storage( table, 'tablesorter-savesort', '' ); }
|
if (ts.storage) { ts.storage( table, 'tablesorter-savesort', '' ); }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user