/** * ========================================================================= * Plugins and other extensions * ========================================================================= */ jtQuery.fn.dataTableExt.oApi.fnGetFilteredNodes = function ( oSettings ) { var anRows = []; for ( var i=0, iLen=oSettings.aiDisplay.length ; i table.dataTable");var o=t.find(".dataTables_scrollBody > table.dataTable");var u=i.innerWidth()+"px";var a=jtQuery("
");i.append(a);u=a.width();a.remove();s.css("width",u);o.css("width",u);r.css("width",u);s.css("table-layout","fixed");o.css("table-layout","fixed");var f=[];o.find("tr").each(function(){var e=jtQuery(this);e.find("td").each(function(e){td_width=getComputedStyle(this,null).width;if(!f[e])f[e]=td_width;else if(f[e]").html(htmlString); var elements = container.find("*").andSelf(); var textNodes = elements.contents().not(elements); textNodes.each(function() { var matches = this.nodeValue.match(expr); if (matches) { var parts = this.nodeValue.split(expr); for (var n = 0; n < parts.length; n++) { if (n) { jtQuery('').text(matches[n - 1]).insertBefore(this); } if (parts[n]) { jtQuery(document.createTextNode(parts[n])).insertBefore(this); } } jtQuery(this).remove(); } }); return container.html(); } /** * ========================================================================= * DataTypes * ========================================================================= */ if(typeof cleanHTMLTags !== 'function') { function cleanHTMLTags(html) { if (html == '') return html; html = html.replace(/<(?:.|\n)*?>/gm, ''); return html; } } if(typeof cleanAndTrim !== 'function') { function cleanAndTrim(str) { str_text = jtQuery("
").html(str).text(); str_text = str_text.replace(/[ ]/gm, "").trim(); return str_text; } } /** * Text with acutes or other string that need localized comparisons */ /* jtQuery.fn.dataTableExt.aTypes.unshift( function ( sData ) { return 'local-str'; } ); */ jtQuery.fn.dataTableExt.oSort['local-str-asc'] = function(a,b) { a = cleanAndTrim(a); b = cleanAndTrim(b); return a.localeCompare(b); }; jtQuery.fn.dataTableExt.oSort['local-str-desc'] = function(a,b) { a = cleanAndTrim(a); b = cleanAndTrim(b); return b.localeCompare(a); }; /** * String Dates * Sort properly dates similar to Monday, 15th of April */ function isDateSystem(str) { if (str == '') return true; var d = Date.parse(str); if (isNaN(d) == false) return true; else return false; } function parseDateSystem(str) { str = cleanHTMLTags(str); str = str.replace(/[ ]/gmi, ""); var d = Date.parse(str); if (isNaN(d) == false) return 0; else return d; } function isDDMMYY(str) { if (str == '') return true; var r = /^(0?[1-9]|[12][0-9]|3[01])[\/\-\.](0?[1-9]|1[012])[\/\-\.]\d{2}$/; return r.test(str); } function parseDDMMYY(str) { if (str == '') return 0; var m = str.match(/^(0?[1-9]|[12][0-9]|3[01])[\/\-\.](0?[1-9]|1[012])[\/\-\.](\d{2})$/); if (m) { var day = parseInt(m[1]); var month = parseInt(m[2])-1; var year = parseInt(m[3]); year = (year>30)?parseInt("19"+ m[3]):parseInt("20"+ m[3]); return new Date(year, month, day).getTime();; } else return 0; } function isMMDDYY(str) { if (str == '') return true; var r = /^(0?[1-9]|1[012])[\/\-\.](0?[1-9]|[12][0-9]|3[01])[\/\-\.]\d{2}$/; return r.test(str); } function parseMMDDYY(str) { if (str == '') return 0; var m = str.match(/^(0?[1-9]|1[012])[\/\-\.](0?[1-9]|[12][0-9]|3[01])[\/\-\.](\d{2})$/); if (m) { var day = parseInt(m[2]); var month = parseInt(m[1])-1; var year = parseInt(m[3]); year = (year>30)?parseInt("19"+ m[3]):parseInt("20"+ m[3]); return new Date(year, month, day).getTime(); } else return 0; } function isMMDDYYYY(str) { if (str == '') return true; var r = /^(0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])[\/\-]\d{4}$/; return r.test(str); } function parseMMDDYYYY(str) { if (str == '') return 0; var m = str.match(/^(0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])[\/\-](\d{4})$/); if (m) { var day = parseInt(m[2]); var month = parseInt(m[1])-1; var year = parseInt(m[3]); return new Date(year, month, day).getTime(); } else return 0; } function isDDMMYYYY(str) { if (str == '') return true; var r = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/; return r.test(str); } function parseDDMMYYYY(str) { if (str == '') return 0; var m = str.match(/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-](\d{4})$/); if (m) { var day = parseInt(m[1]); var month = parseInt(m[2])-1; var year = parseInt(m[3]); return new Date(year, month, day).getTime(); } else return 0; } jtQuery.fn.dataTableExt.oSort['date-str-asc'] = function(a,b) { var x = parseDateStrType(a, 'asc'), y = parseDateStrType(b, 'asc'); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }; jtQuery.fn.dataTableExt.oSort['date-str-desc'] = function(a,b) { var x = parseDateStrType(a, 'desc'), y = parseDateStrType(b, 'desc'); return ((x < y) ? 1 : ((x > y) ? -1 : 0)); }; function isDateStrType(str) { return isDateSystem(str); } function parseDateStrType(str) { str = cleanAndTrim(str); return parseDateSystem(str); } /* jtQuery.fn.dataTableExt.aTypes.unshift( function ( sData ) { sData = cleanAndTrim(sData); if (sData == "") return 'date-str'; if (isDateStrType(sData)) return 'date-str'; else return null; } ); */ /** * Forced Comma Formatted Number */ function getForcedCommaFormattedNumber (str) { var r = /^[+-]?\d+(\.\d{3})*\,?\d*$/; if (r.test(str)) { x = str.replace( /\./g, "" ); x = x.replace( /,/, "." ); x = parseFloat( x ); } else { x = parseFloat ( str); } return x; } function parseForcedCommaFormattedNumber(a, sorting_order) { var empty_value = (sorting_order == 'asc') ? Number.MAX_VALUE : -Number.MAX_VALUE; a = jtQuery("
").html(a).text(); a = cleanHTMLTags(a); a = a.replace(/[^0-9.,\-\+]/g, ""); if (( a == "-" ) || (a == "+") || (a == "")) a = empty_value; else a = getForcedCommaFormattedNumber(a); return a; } jtQuery.fn.dataTableExt.oSort['forced-numeric-comma-asc'] = function(a,b) { var x = parseForcedCommaFormattedNumber(a, 'asc'), y = parseForcedCommaFormattedNumber(b, 'asc'); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }; jtQuery.fn.dataTableExt.oSort['forced-numeric-comma-desc'] = function(a,b) { var x = parseForcedCommaFormattedNumber(a, 'desc'), y = parseForcedCommaFormattedNumber(b, 'desc'); return ((x < y) ? 1 : ((x > y) ? -1 : 0)); }; /** * Forced Period Formatted Number */ function getForcedPeriodFormattedNumber (str) { var r = /^[+-]?\d+(,\d{3})*\.?\d*$/; if (r.test(str)) { x = str.replace( /,/g, "" ); x = parseFloat( x ); } else { x = parseFloat ( str); } return x; } function parseForcedPeriodFormattedNumber(a, sorting_order) { var empty_value = (sorting_order == 'asc') ? Number.MAX_VALUE : -Number.MAX_VALUE; a = jtQuery("
").html(a).text(); a = cleanHTMLTags(a); a = a.replace(/[^0-9.,\-\+]/g, ""); if (( a == "-" ) || (a == "+") || (a == "")) a = empty_value; else a = getForcedPeriodFormattedNumber(a); return a; } jtQuery.fn.dataTableExt.oSort['forced-numeric-period-asc'] = function(a,b) { var x = parseForcedPeriodFormattedNumber(a, 'asc'), y = parseForcedPeriodFormattedNumber(b, 'asc'); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }; jtQuery.fn.dataTableExt.oSort['forced-numeric-period-desc'] = function(a,b) { var x = parseForcedPeriodFormattedNumber(a, 'desc'), y = parseForcedPeriodFormattedNumber(b, 'desc'); return ((x < y) ? 1 : ((x > y) ? -1 : 0)); }; /** * Comma Separated Numbers * Sort properly numbers with commas that may be enclosed in HTML tags, e.g. 1,000 1,100,090 1,234.56 1000, $100, 5% 3.2% */ if(typeof overwriteCommaFormattedNumberWithCustom !== 'boolean') { function isCommaFormattedNumber (str) { var r1 = /^[+-]?\d+(,\d{3})*\.?\d*$/; var r2 = /^[+-]?\d+(\.\d{3})*\,?\d*$/; var r3 = /^[+-]?\d+(,\d+)$/; if (r1.test(str)) { regex_id = 1; return true; } else if (r2.test(str)) { regex_id = 2; return true; } else if (r3.test(str)) { regex_id = 3; return true; } else { regex_id = 0; return false; } } function getCommaFormattedNumber (str) { var r1 = /^[+-]?\d+(,\d{3})*\.?\d*$/; var r2 = /^[+-]?\d+(\.\d{3})*\,?\d*$/; var r3 = /^[+-]?\d+(,\d+)$/; var regex_id = 0; if (r1.test(str)) { regex_id = 1; } else if (r2.test(str)) { regex_id = 2; } else if (r3.test(str)) { regex_id = 3; } else { regex_id = 0; return str; } var x = null; switch (regex_id) { case 1: x = str.replace( /,/g, "" ); break; case 2: x = str.replace( /\./g, "" ); x = x.replace( /,/, "." ); break; case 3: x = str.replace( /,/, "." ); break; default: // we should never reach this line! return str; } x = parseFloat( x ); return x; } function parseCommaFormattedNumber(a, sorting_order) { var empty_value = (sorting_order == 'asc') ? Number.MAX_VALUE : -Number.MAX_VALUE; a = jtQuery("
").html(a).text(); a = cleanHTMLTags(a); a = a.replace(/[\s| ]/gmi, "").replace(/[\+|%|\$|\£|\€]/gm,""); if (( a == "-" ) || (a == "+") || (a == "")) a = empty_value; else a = getCommaFormattedNumber(a); return a; } jtQuery.fn.dataTableExt.aTypes.unshift( function ( sData ) { sData = jtQuery("
").html(sData).text(); sData = cleanHTMLTags(sData); sData = sData.replace(/[\s| ]/gmi, "").replace(/[\+|%|\$|\£|\€]/gm,""); if (sData == "") return 'numeric-comma'; if (isCommaFormattedNumber(sData)) return 'numeric-comma'; else return null; } ); jtQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function(a,b) { var x = parseCommaFormattedNumber(a, 'asc'), y = parseCommaFormattedNumber(b, 'asc'); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }; jtQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) { var x = parseCommaFormattedNumber(a, 'desc'), y = parseCommaFormattedNumber(b, 'desc'); return ((x < y) ? 1 : ((x > y) ? -1 : 0)); }; }