mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Parsers: Add jQuery Globalize parser
Fix input-numeric parser to allow parsing a zero value
This commit is contained in:
parent
f98ad57499
commit
de9421bda8
4
dist/js/parsers/parser-globalize.min.js
vendored
Normal file
4
dist/js/parsers/parser-globalize.min.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/*! Parser: jQuery Globalize - updated 5/2/2015 (v2.21.6) */
|
||||||
|
!function(a){"use strict";/*! jQuery Globalize date parser (https://github.com/jquery/globalize#date-module) */
|
||||||
|
a.tablesorter.addParser({id:"globalize-date",is:function(){return!1},format:function(a,b,c,d){var e=b.config,f=e.globalize&&(e.globalize[d]||e.globalize)||{},g=Globalize&&Globalize.dateParser?Globalize.dateParser(f)(a):a?new Date(a):a;return g instanceof Date&&isFinite(g)?g.getTime():a},type:"numeric"}),/*! jQuery Globalize number parser (https://github.com/jquery/globalize#number-module) */
|
||||||
|
a.tablesorter.addParser({id:"globalize-number",is:function(){return!1},format:function(b,c,d,e){var f=c.config,g=f.globalize&&(f.globalize[e]||f.globalize)||{},h=Globalize&&Globalize.numberParser?Globalize.numberParser(g)(b):b?a.tablesorter.formatFloat((b||"").replace(/[^\w,. \-()]/g,""),c):b;return b&&"number"==typeof h?h:b},type:"numeric"})}(jQuery);
|
2
dist/js/parsers/parser-input-select.min.js
vendored
2
dist/js/parsers/parser-input-select.min.js
vendored
@ -1,2 +1,2 @@
|
|||||||
/*! Parser: input & select - updated 4/28/2015 (v2.21.6) */
|
/*! Parser: input & select - updated 4/28/2015 (v2.21.6) */
|
||||||
!function(a){"use strict";var b=function(){};a.tablesorter.addParser({id:"inputs",is:function(){return!1},format:function(b,c,d){return a(d).find("input").val()||b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"inputs-numeric",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input").val()||b,f=a.tablesorter.formatFloat((e||"").replace(/[^\w,. \-()]/g,""),c);return f&&"number"==typeof f?f:b?a.trim(b&&c.config.ignoreCase?b.toLocaleLowerCase():b):b},parsed:!0,type:"numeric"}),a.tablesorter.addParser({id:"checkbox",is:function(){return!1},format:function(b,c,d,e){var f=a(d),g=c.config.widgetOptions,h=g.group_checkbox?g.group_checkbox:["checked","unchecked"],i=f.find('input[type="checkbox"]'),j=i.length?i[0].checked:"";return f.closest("tr").toggleClass("checked-"+e,j),i.length?h[j?0:1]:b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select",is:function(){return!1},format:function(b,c,d){return a(d).find("select").val()||b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select-text",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.find("option:selected").text()||"":b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"textarea",is:function(){return!1},format:function(b,c,d){return a(d).find("textarea").val()||b},parsed:!0,type:"text"}),a(function(){a("table").on("tablesorter-initialized",function(){var c=function(b){b&&a(":focus").blur()};a(this).children("tbody").on("mouseleave",function(a){c("TBODY"===a.target.nodeName)}).on("focus","select, input, textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur","input, textarea",function(){this.value=a(this).data("ts-original-value")}).on("change keyup","select, input, textarea",function(d){if(27===d.which)return void(this.value=a(this).data("ts-original-value"));if("change"===d.type||"keyup"===d.type&&13===d.which&&("INPUT"===d.target.nodeName||"TEXTAREA"===d.target.nodeName&&d.altKey)){var e,f=a(d.target),g=f.closest("td"),h=g.closest("table"),i=g[0].cellIndex,j=h[0].config||!1,k=j&&j.$headers&&j.$headers.eq(i);if(!j||k&&k.length&&(k.hasClass("parser-false")||k.hasClass("sorter-false")&&k.hasClass("filter-false")))return c();(f.val()!==f.data("ts-original-value")||"checkbox"===d.target.type)&&(f.data("ts-original-value",f.val()),h.trigger("updateCell",[f.closest("td"),e,function(){b(d,h,f)}]))}})})})}(jQuery);
|
!function(a){"use strict";var b=function(){};a.tablesorter.addParser({id:"inputs",is:function(){return!1},format:function(b,c,d){return a(d).find("input").val()||b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"inputs-numeric",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input").val()||b,f=a.tablesorter.formatFloat((e||"").replace(/[^\w,. \-()]/g,""),c);return b&&"number"==typeof f?f:b?a.trim(b&&c.config.ignoreCase?b.toLocaleLowerCase():b):b},parsed:!0,type:"numeric"}),a.tablesorter.addParser({id:"checkbox",is:function(){return!1},format:function(b,c,d,e){var f=a(d),g=c.config.widgetOptions,h=g.group_checkbox?g.group_checkbox:["checked","unchecked"],i=f.find('input[type="checkbox"]'),j=i.length?i[0].checked:"";return f.closest("tr").toggleClass("checked-"+e,j),i.length?h[j?0:1]:b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select",is:function(){return!1},format:function(b,c,d){return a(d).find("select").val()||b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select-text",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.find("option:selected").text()||"":b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"textarea",is:function(){return!1},format:function(b,c,d){return a(d).find("textarea").val()||b},parsed:!0,type:"text"}),a(function(){a("table").on("tablesorter-initialized",function(){var c=function(b){b&&a(":focus").blur()};a(this).children("tbody").on("mouseleave",function(a){c("TBODY"===a.target.nodeName)}).on("focus","select, input, textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur","input, textarea",function(){this.value=a(this).data("ts-original-value")}).on("change keyup","select, input, textarea",function(d){if(27===d.which)return void(this.value=a(this).data("ts-original-value"));if("change"===d.type||"keyup"===d.type&&13===d.which&&("INPUT"===d.target.nodeName||"TEXTAREA"===d.target.nodeName&&d.altKey)){var e,f=a(d.target),g=f.closest("td"),h=g.closest("table"),i=g[0].cellIndex,j=h[0].config||!1,k=j&&j.$headers&&j.$headers.eq(i);if(!j||k&&k.length&&(k.hasClass("parser-false")||k.hasClass("sorter-false")&&k.hasClass("filter-false")))return c();(f.val()!==f.data("ts-original-value")||"checkbox"===d.target.type)&&(f.data("ts-original-value",f.val()),h.trigger("updateCell",[f.closest("td"),e,function(){b(d,h,f)}]))}})})})}(jQuery);
|
@ -16,7 +16,6 @@
|
|||||||
<!-- Tablesorter: required -->
|
<!-- Tablesorter: required -->
|
||||||
<link rel="stylesheet" href="../css/theme.blue.css">
|
<link rel="stylesheet" href="../css/theme.blue.css">
|
||||||
<script src="../js/jquery.tablesorter.js"></script>
|
<script src="../js/jquery.tablesorter.js"></script>
|
||||||
<script src="../addons/pager/jquery.tablesorter.pager.js"></script>
|
|
||||||
<script src="../js/parsers/parser-input-select.js"></script>
|
<script src="../js/parsers/parser-input-select.js"></script>
|
||||||
|
|
||||||
<script id="js">// add parser through the tablesorter addParser method
|
<script id="js">// add parser through the tablesorter addParser method
|
||||||
|
@ -538,6 +538,7 @@
|
|||||||
<li><a href="example-parsers-date-range.html">Date Range parsers</a> (<span class="version">v2.21.0</span>); if filters, include the <a href="example-widget-filter-custom-search2.html">insideRange</a> filter search type.</li>
|
<li><a href="example-parsers-date-range.html">Date Range parsers</a> (<span class="version">v2.21.0</span>); if filters, include the <a href="example-widget-filter-custom-search2.html">insideRange</a> filter search type.</li>
|
||||||
<li><a href="example-parsers-duration.html">Duration parser</a> (<span class="version">v2.17.8</span>).</li>
|
<li><a href="example-parsers-duration.html">Duration parser</a> (<span class="version">v2.17.8</span>).</li>
|
||||||
<li><a href="example-parsers-file-type.html">File type parser</a> (<span class="version">v2.13</span>).</li>
|
<li><a href="example-parsers-file-type.html">File type parser</a> (<span class="version">v2.13</span>).</li>
|
||||||
|
<li><a href="http://jsfiddle.net/Mottie/0j18Lw8r/">jQuery Globalize</a> (number & date parsers; <span class="version">v2.21.6</span>).</li>
|
||||||
<li><a href="example-parsers-ignore-articles.html">Ignore leading articles parser</a> (Ignore "A", "An" and "The" in titles) (<span class="version">v2.8</span>).</li>
|
<li><a href="example-parsers-ignore-articles.html">Ignore leading articles parser</a> (Ignore "A", "An" and "The" in titles) (<span class="version">v2.8</span>).</li>
|
||||||
<li><a href="example-widget-grouping.html">Input/select parsers</a> (used by Grouping rows widget) (<span class="version">v2.8</span>; <span class="version updated">v2.21.3</span>).</li>
|
<li><a href="example-widget-grouping.html">Input/select parsers</a> (used by Grouping rows widget) (<span class="version">v2.8</span>; <span class="version updated">v2.21.3</span>).</li>
|
||||||
<li><a href="example-parsers-feet-inch-fraction.html">Feet-inch-fraction parser</a> (<span class="version">v2.8</span>).</li>
|
<li><a href="example-parsers-feet-inch-fraction.html">Feet-inch-fraction parser</a> (<span class="version">v2.8</span>).</li>
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
/* Extract dates using popular natural language date parsers */
|
/* Extract dates using popular natural language date parsers */
|
||||||
/*jshint jquery:true */
|
/*jshint jquery:true */
|
||||||
;(function($){
|
;(function($){
|
||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
/*! Sugar (http://sugarjs.com/dates#comparing_dates) */
|
/*! Sugar (http://sugarjs.com/dates#comparing_dates) */
|
||||||
/* demo: http://jsfiddle.net/Mottie/abkNM/4163/ */
|
/* demo: http://jsfiddle.net/Mottie/abkNM/4163/ */
|
||||||
$.tablesorter.addParser({
|
$.tablesorter.addParser({
|
||||||
id: "sugar",
|
id: 'sugar',
|
||||||
is: function() {
|
is: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@ -15,13 +15,13 @@
|
|||||||
var date = Date.create ? Date.create(s) : s ? new Date(s) : s;
|
var date = Date.create ? Date.create(s) : s ? new Date(s) : s;
|
||||||
return date instanceof Date && isFinite(date) ? date.getTime() : s;
|
return date instanceof Date && isFinite(date) ? date.getTime() : s;
|
||||||
},
|
},
|
||||||
type: "numeric"
|
type: 'numeric'
|
||||||
});
|
});
|
||||||
|
|
||||||
/*! Datejs (http://www.datejs.com/) */
|
/*! Datejs (http://www.datejs.com/) */
|
||||||
/* demo: http://jsfiddle.net/Mottie/abkNM/4164/ */
|
/* demo: http://jsfiddle.net/Mottie/abkNM/4164/ */
|
||||||
$.tablesorter.addParser({
|
$.tablesorter.addParser({
|
||||||
id: "datejs",
|
id: 'datejs',
|
||||||
is: function() {
|
is: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@ -29,7 +29,7 @@
|
|||||||
var date = Date.parse ? Date.parse(s) : s ? new Date(s) : s;
|
var date = Date.parse ? Date.parse(s) : s ? new Date(s) : s;
|
||||||
return date instanceof Date && isFinite(date) ? date.getTime() : s;
|
return date instanceof Date && isFinite(date) ? date.getTime() : s;
|
||||||
},
|
},
|
||||||
type: "numeric"
|
type: 'numeric'
|
||||||
});
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
46
js/parsers/parser-globalize.js
Normal file
46
js/parsers/parser-globalize.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*! Parser: jQuery Globalize - updated 5/2/2015 (v2.21.6) */
|
||||||
|
/* Extract localized data using jQuery's Globalize parsers; set
|
||||||
|
Globalize.locale( 'xx' ) prior to initializing tablesorter! */
|
||||||
|
/*jshint jquery:true */
|
||||||
|
;( function( $ ) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/*! jQuery Globalize date parser (https://github.com/jquery/globalize#date-module) */
|
||||||
|
/* demo: http://jsfiddle.net/Mottie/0j18Lw8r/ */
|
||||||
|
$.tablesorter.addParser({
|
||||||
|
id: 'globalize-date',
|
||||||
|
is: function () {
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
format: function ( str, table, cell, cellIndex ) {
|
||||||
|
var c = table.config,
|
||||||
|
// add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' }
|
||||||
|
// or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } }
|
||||||
|
options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {},
|
||||||
|
date = Globalize && Globalize.dateParser ? Globalize.dateParser( options )( str ) :
|
||||||
|
str ? new Date( str ) : str;
|
||||||
|
return date instanceof Date && isFinite( date ) ? date.getTime() : str;
|
||||||
|
},
|
||||||
|
type: 'numeric'
|
||||||
|
});
|
||||||
|
|
||||||
|
/*! jQuery Globalize number parser (https://github.com/jquery/globalize#number-module) */
|
||||||
|
/* demo: http://jsfiddle.net/Mottie/0j18Lw8r/ */
|
||||||
|
$.tablesorter.addParser({
|
||||||
|
id: 'globalize-number',
|
||||||
|
is: function () {
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
format: function ( str, table, cell, cellIndex ) {
|
||||||
|
var c = table.config,
|
||||||
|
// add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' }
|
||||||
|
// or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } }
|
||||||
|
options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {},
|
||||||
|
num = Globalize && Globalize.numberParser ? Globalize.numberParser( options )( str ) :
|
||||||
|
str ? $.tablesorter.formatFloat( ( str || '' ).replace( /[^\w,. \-()]/g, '' ), table ) : str;
|
||||||
|
return str && typeof num === 'number' ? num : str;
|
||||||
|
},
|
||||||
|
type: 'numeric'
|
||||||
|
});
|
||||||
|
|
||||||
|
})( jQuery );
|
@ -35,7 +35,7 @@
|
|||||||
format: function(s, table, cell) {
|
format: function(s, table, cell) {
|
||||||
var v = $(cell).find('input').val() || s,
|
var v = $(cell).find('input').val() || s,
|
||||||
n = $.tablesorter.formatFloat((v || '').replace(/[^\w,. \-()]/g, ''), table);
|
n = $.tablesorter.formatFloat((v || '').replace(/[^\w,. \-()]/g, ''), table);
|
||||||
return n && typeof n === 'number' ? n :
|
return s && typeof n === 'number' ? n :
|
||||||
s ? $.trim( s && table.config.ignoreCase ? s.toLocaleLowerCase() : s ) : s;
|
s ? $.trim( s && table.config.ignoreCase ? s.toLocaleLowerCase() : s ) : s;
|
||||||
},
|
},
|
||||||
parsed : true, // filter widget flag
|
parsed : true, // filter widget flag
|
||||||
|
Loading…
Reference in New Issue
Block a user