Core: an empty string headerTemplate option will now prevent adding an inner div to the header

This commit is contained in:
Mottie 2014-09-12 11:08:39 -05:00
parent ec019b387c
commit d4d96e85f1
2 changed files with 51 additions and 7 deletions

View File

@ -447,14 +447,16 @@
ch = ts.getColumnData( table, c.headers, index, true );
// save original header content
c.headerContent[index] = $(this).html();
// set up header template
t = c.headerTemplate.replace(/\{content\}/g, $(this).html()).replace(/\{icon\}/g, i);
if (c.onRenderTemplate) {
h = c.onRenderTemplate.apply($t, [index, t]);
if (h && typeof h === 'string') { t = h; } // only change t if something is returned
// if headerTemplate is empty, don't reformat the header cell
if ( c.headerTemplate !== '' ) {
// set up header template
t = c.headerTemplate.replace(/\{content\}/g, $(this).html()).replace(/\{icon\}/g, i);
if (c.onRenderTemplate) {
h = c.onRenderTemplate.apply($t, [index, t]);
if (h && typeof h === 'string') { t = h; } // only change t if something is returned
}
$(this).html('<div class="' + ts.css.headerIn + '">' + t + '</div>'); // faster than wrapInner
}
$(this).html('<div class="' + ts.css.headerIn + '">' + t + '</div>'); // faster than wrapInner
if (c.onRenderHeader) { c.onRenderHeader.apply($t, [index]); }
this.column = parseInt( $(this).attr('data-column'), 10);
this.order = formatSortingOrder( ts.getData($t, ch, 'sortInitialOrder') || c.sortInitialOrder ) ? [1,0,2] : [0,1,2];

View File

@ -0,0 +1,42 @@
/*! Duration parser
*/
/*jshint jquery:true, unused:false */
;(function($){
"use strict";
$.tablesorter.defaults.durationLabels = 'y,d,h,m,s';
// If any number > 9999, then set table.config.durationLength = 5
// The below regex matches this duration example: 1y 23d 12h 44m 9s
$.tablesorter.addParser({
id: "duration",
is: function() {
return false;
},
format: function(s, table) {
var i, time,
c = table.config,
t = '',
duration = '',
len = c.durationLength || 4,
str = new Array(len + 1).join('0'),
labels = (c.durationLabels || 'y,d,h,m,s').split(/\s*,\s*/),
llen = labels.length;
if (!c.durationRegex) {
for (i = 0; i < llen; i++) {
t += '(?:(\\d+)' + labels[i] + '\\s*)?';
}
c.durationRegex = new RegExp(t, 'i');
}
time = s.match(c.durationRegex);
for (i = 1; i < llen + 1; i++) {
duration += ( str + ( time[i] || 0 ) ).slice(-len);
}
console.log(duration, s, time);
return duration;
},
type: "text"
});
})(jQuery);