diff --git a/dist/js/widgets/widget-grouping.min.js b/dist/js/widgets/widget-grouping.min.js index 4b6c0194..0eff235c 100644 --- a/dist/js/widgets/widget-grouping.min.js +++ b/dist/js/widgets/widget-grouping.min.js @@ -5,32 +5,55 @@ */ /*jshint browser:true, jquery:true, unused:false */ /*global jQuery: false */ -!function(a){"use strict";var b=a.tablesorter;b.grouping={types:{number:function(a,c,d,e,f){var g,h;return e>1&&""!==d?c.hasClass(b.css.sortAsc)?(g=Math.floor(parseFloat(d)/e)*e,g>parseFloat(f||0)?g:parseFloat(f||0)):(g=Math.ceil(parseFloat(d)/e)*e,g=e?h[e-1]:d||"")},separator:function(b,c,d,e){var f=(d+"").split(b.widgetOptions.group_separator);return a.trim(f&&e>0&&f.length>=e?f[(e||1)-1]:"")},word:function(a,b,c,d){var e=(c+" ").match(/\w+/g);return e&&e.length>=d?e[d-1]:c||""},letter:function(a,b,c,d){return c?(c+" ").substring(0,d):""},date:function(a,c,d,e,f){var g,h,i=a.widgetOptions,j=new Date(d||""); +!function(a){"use strict";var b=a.tablesorter,c=b.grouping={types:{number:function(a,c,d,e){var f,g=c.hasClass(b.css.sortAsc); +// show range +return e>1&&""!==d?(f=g?Math.floor(parseFloat(d)/e)*e:Math.ceil(parseFloat(d)/e)*e,f+=" - "+(f+(e-1)*(g?1:-1))):f=parseFloat(d)||d,f},separator:function(b,c,d,e){var f=(d+"").split(b.widgetOptions.group_separator); +// return $.trim(word && num > 0 && word.length >= num ? word[(num || 1) - 1] : ''); +return a.trim(f[e-1]||"")},text:function(a,b,c){return c},word:function(a,b,c,d){var e=(c+" ").match(/\w+/g)||[]; +// return word && word.length >= num ? word[num - 1] : txt || ''; +return e[d-1]||""},letter:function(a,b,c,d){return c?(c+" ").substring(0,d):""},date:function(a,b,d,e,f){var g,h,i=a.widgetOptions,j=new Date(d||""); // check for valid date // check for valid date -return j instanceof Date&&isFinite(j)?(g=j.getFullYear(),h=b.grouping.findMonth(i,j.getMonth()),"year"===e?g:"month"===e?h:"monthyear"===e?h+" "+g:"day"===e?h+" "+j.getDate():"week"===e?b.grouping.findWeek(i,j.getDay()):"time"===e?b.grouping.findTime(i,j):i.group_dateString(j,a,c)):i.group_dateInvalid}}, +return j instanceof Date&&isFinite(j)?(g=j.getFullYear(),h=c.findMonth(i,j.getMonth()),"year"===e?g:"month"===e?h:"monthyear"===e?h+" "+g:"day"===e?h+" "+j.getDate():"week"===e?c.findWeek(i,j.getDay()):"time"===e?c.findTime(i,j):i.group_dateString(j,a,b)):i.group_dateInvalid}}, // group date type functions to allow using this widget with Globalize findMonth:function(a,b){ // CLDR returns an object { 1: "Jan", 2: "Feb", 3: "Mar", ..., 12: "Dec" } return a.group_months[b+(""===(a.group_months[0]||"")?1:0)]},findWeek:function(b,c){if(a.isArray(b.group_week))return b.group_week[c];if(!a.isEmptyObject(b.group_week)){ // CLDR returns { sun: "Sun", mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", ... } -var d=["sun","mon","tue","wed","thu","fri","sat"];return b.group_week[d[c]]}},findTime:function(a,b){var c,d=b.getHours(),e=d>=12?1:0, +var d=["sun","mon","tue","wed","thu","fri","sat"];return b.group_week[d[c]]}},findTime:function(a,b){var c, // CLDR returns { am: "AM", pm: "PM", ... } -f=a.group_time.am&&a.group_time.pm,g=("00"+(a.group_time24Hour&&d>12?d-12:a.group_time24Hour&&0===d?d+12:d)).slice(-2),h=("00"+b.getMinutes()).slice(-2);return c=a.group_time[f?["am","pm"][e]:e],g+":"+h+(a.group_time24Hour?"":" "+(c||""))},update:function(c,d,e){if(!a.isEmptyObject(d.cache)){var f,g,h,i,j,k,l,m,n,o,p=b.hasWidget(c,"pager"),q="undefined"!=typeof d.sortList[0],r="",s=0,t=!1,u=a.isArray(e.group_forceColumn)&&"undefined"!=typeof e.group_forceColumn[0]?e.group_enforceSort&&!q?-1:e.group_forceColumn[0]:q?d.sortList[0][0]:-1;if(d.$table.find("tr.group-hidden").removeClass("group-hidden").end().find("tr.group-header").remove(),e.group_collapsible&& +d=a.group_time.am&&a.group_time.pm,e=b.getHours(),f=e>=12?1:0,g=a.group_time24Hour&&e>12?e-12:a.group_time24Hour&&0===e?e+12:e,h=("00"+g).slice(-2),i=("00"+b.getMinutes()).slice(-2);return c=a.group_time[d?["am","pm"][f]:f],h+":"+i+(a.group_time24Hour?"":" "+(c||""))},update:function(b,d,e){if(!a.isEmptyObject(d.cache)){var f="undefined"!=typeof d.sortList[0],g={},h=a.isArray(e.group_forceColumn)&&"undefined"!=typeof e.group_forceColumn[0]?e.group_enforceSort&&!f?-1:e.group_forceColumn[0]:f?d.sortList[0][0]:-1;d.$table.find("tr.group-hidden").removeClass("group-hidden").end().find("tr.group-header").remove(),e.group_collapsible&& // clear pager saved spacer height (in case the rows are collapsed) -d.$table.data("pagerSavedHeight",0),u>=0&&uf;f++)i=l[f][d.columns].$row,i.is(":visible")&&b.grouping.types[k[1]]&&(h=l[f]?b.grouping.types[k[1]](d,d.$headerIndexed[u],l[f][u],/date/.test(j)?k[2]:parseInt(k[2]||1,10)||1,r):h,r!==h&&(r=h,"number"===k[1]&&k[2]>1&&""!==h&&(h+=" - "+(parseInt(h,10)+(parseInt(k[2],10)-1)*(d.$headerIndexed[u].hasClass(b.css.sortAsc)?1:-1))),a.isFunction(e.group_formatter)&&(h=e.group_formatter((h||"").toString(),u,c,d,e)||h),i.before(''+(e.group_collapsible?"":"")+''+h+''),e.group_saveGroups&&!t&&e.group_collapsed&&e.group_collapsible&&e.group_currentGroups[e.group_currentGroup].push(h)));d.$table.find("tr.group-header").bind("selectstart",!1).each(function(){var b,d,f,g=a(this),h=g.nextUntil("tr.group-header").filter(":visible");(e.group_count||a.isFunction(e.group_callback))&&(d=g.find(".group-count"),d.length&&(e.group_count&&d.html(e.group_count.replace(/\{num\}/g,h.length)),a.isFunction(e.group_callback)&&e.group_callback(g.find("td"),h,u,c))),e.group_saveGroups&&!a.isEmptyObject(e.group_currentGroups)&&e.group_currentGroups[e.group_currentGroup].length?(f=g.find(".group-name").text().toLowerCase()+g.attr("data-group-index"),b=a.inArray(f,e.group_currentGroups[e.group_currentGroup])>-1,g.toggleClass("collapsed",b),h.toggleClass("group-hidden",b)):e.group_collapsed&&e.group_collapsible&&(g.addClass("collapsed"),h.addClass("group-hidden"))}),d.$table.trigger(e.group_complete)}}},bindEvents:function(c,d,e){e.group_collapsible&&(e.group_currentGroups=[], +d.$table.data("pagerSavedHeight",0),h>=0&&he;e++)j=k.eq(e),i=j.nextUntil("tr.group-header").filter(":visible"),(c.group_count||a.isFunction(c.group_callback))&&(g=j.find(".group-count"),g.length&&(c.group_count&&g.html(c.group_count.replace(/\{num\}/g,i.length)),a.isFunction(c.group_callback)&&c.group_callback(j.find("td"),i,d.column,b.table))),c.group_saveGroups&&!a.isEmptyObject(c.group_collapsedGroups)&&c.group_collapsedGroups[c.group_collapsedGroup].length?(h=j.find(".group-name").text().toLowerCase()+j.attr("data-group-index"),f=a.inArray(h,c.group_collapsedGroups[c.group_collapsedGroup])>-1,j.toggleClass("collapsed",f),i.toggleClass("group-hidden",f)):c.group_collapsed&&c.group_collapsible&&(j.addClass("collapsed"),i.addClass("group-hidden"))},groupHeaderHTML:function(a,b,c){return''+(b.group_collapsible?"":"")+''+c.currentGroup+''},saveCurrentGrouping:function(a,c,d){ +// save current grouping +var e,f,g=!1; +// include direction when saving groups (reversed numbers shows different range values) +// combine column, sort direction & grouping as save key +return c.group_collapsible&&c.group_saveGroups&&b.storage&&(c.group_collapsedGroups=b.storage(a.table,"tablesorter-groups")||{},f="dir"+a.sortList[0][1],e=c.group_collapsedGroup=""+a.sortList[0][0]+f+d.grouping.join(""),c.group_collapsedGroups[e]?g=!0:c.group_collapsedGroups[e]=[]),g},findColumnGroups:function(a,d,e){var f,g,h,i,j=b.hasWidget(a.table,"pager");for(e.groupIndex=0,f=0;fh;h++)e.rowData=g[h],e.$row=e.rowData[a.columns].$row, +// fixes #438 +e.$row.is(":visible")&&c.types[e.grouping[1]]&&c.insertGroupHeader(a,d,e)},insertGroupHeader:function(b,d,e){var f=b.$headerIndexed[e.column],g=e.rowData[e.column],h=/date/.test(e.groupClass)?e.grouping[2]:parseInt(e.grouping[2]||1,10)||1;e.currentGroup=e.rowData?c.types[e.grouping[1]](b,f,g,h,e.group):e.currentGroup,e.group!==e.currentGroup&&(e.group=e.currentGroup,a.isFunction(d.group_formatter)&&(e.currentGroup=d.group_formatter((e.group||"").toString(),e.column,b.table,b,d)||e.group),e.$row.before(c.groupHeaderHTML(b,d,e)),d.group_saveGroups&&!e.savedGroup&&d.group_collapsed&&d.group_collapsible&& +// all groups start collapsed +d.group_collapsedGroups[d.group_collapsedGroup].push(e.currentGroup))},bindEvents:function(d,e,f){f.group_collapsible&&(f.group_collapsedGroups=[], // .on() requires jQuery 1.7+ -d.$table.on("click toggleGroup keyup","tr.group-header",function(f){ +e.$table.on("click toggleGroup keyup","tr.group-header",function(c){ // pressing enter will toggle the group -if(f.stopPropagation(),"keyup"!==f.type||13===f.which){var g,h,i,j=a(this),k=j.find(".group-name").text().toLowerCase()+j.attr("data-group-index"); +if(c.stopPropagation(),"keyup"!==c.type||13===c.which){var g,h,i,j=a(this),k=j.find(".group-name").text().toLowerCase()+j.attr("data-group-index"); // use shift-click to toggle ALL groups -!f.shiftKey||"click"!==f.type&&"keyup"!==f.type||j.siblings(".group-header").trigger("toggleGroup"),j.toggleClass("collapsed"), +!c.shiftKey||"click"!==c.type&&"keyup"!==c.type||j.siblings(".group-header").trigger("toggleGroup"),j.toggleClass("collapsed"), // nextUntil requires jQuery 1.4+ j.nextUntil("tr.group-header").toggleClass("group-hidden",j.hasClass("collapsed")), // save collapsed groups -e.group_saveGroups&&b.storage&&(h=d.$table.find(".group-header"),g=j.hasClass("collapsed"),e.group_currentGroups[e.group_currentGroup]||(e.group_currentGroups[e.group_currentGroup]=[]),g&&e.group_currentGroup?e.group_currentGroups[e.group_currentGroup].push(k):e.group_currentGroup&&(i=a.inArray(k,e.group_currentGroups[e.group_currentGroup]),i>-1&&e.group_currentGroups[e.group_currentGroup].splice(i,1)),b.storage(c,"tablesorter-groups",e.group_currentGroups))}})),a(e.group_saveReset).on("click",function(){b.grouping.clearSavedGroups(c)}),d.$table.on("pagerChange.tsgrouping",function(){b.grouping.update(c,d,e)})},clearSavedGroups:function(a){a&&b.storage&&(b.storage(a,"tablesorter-groups",""),b.grouping.update(a,a.config,a.config.widgetOptions))}},b.addWidget({id:"group",priority:100,options:{group_collapsible:!0,// make the group header clickable and collapse the rows below it. +f.group_saveGroups&&b.storage&&(h=e.$table.find(".group-header"),g=j.hasClass("collapsed"),f.group_collapsedGroups[f.group_collapsedGroup]||(f.group_collapsedGroups[f.group_collapsedGroup]=[]),g&&f.group_collapsedGroup?f.group_collapsedGroups[f.group_collapsedGroup].push(k):f.group_collapsedGroup&&(i=a.inArray(k,f.group_collapsedGroups[f.group_collapsedGroup]),i>-1&&f.group_collapsedGroups[f.group_collapsedGroup].splice(i,1)),b.storage(d,"tablesorter-groups",f.group_collapsedGroups))}})),a(f.group_saveReset).on("click",function(){c.clearSavedGroups(d)}),e.$table.on("pagerChange.tsgrouping",function(){c.update(d,e,f)})},clearSavedGroups:function(a){a&&b.storage&&(b.storage(a,"tablesorter-groups",""),c.update(a,a.config,a.config.widgetOptions))}};b.addWidget({id:"group",priority:100,options:{group_collapsible:!0,// make the group header clickable and collapse the rows below it. group_collapsed:!1,// start with all groups collapsed group_saveGroups:!0,// remember collapsed groups group_saveReset:null,// element to clear saved collapsed groups @@ -53,4 +76,4 @@ group_dateInvalid:"Invalid Date", // this function is used when 'group-date' is set to create the date string // you can just return date, date.toLocaleString(), date.toLocaleDateString() or d.toLocaleTimeString() // reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Conversion_getter -group_dateString:function(a){return a.toLocaleString()}},init:function(a,c,d,e){b.grouping.bindEvents(a,d,e)},format:function(a,c,d){b.grouping.update(a,c,d)},remove:function(a,b,c){b.$table.off("click","tr.group-header").off("pagerChange.tsgrouping").find(".group-hidden").removeClass("group-hidden").end().find("tr.group-header").remove()}})}(jQuery); \ No newline at end of file +group_dateString:function(a){return a.toLocaleString()}},init:function(a,b,d,e){c.bindEvents(a,d,e)},format:function(a,b,d){c.update(a,b,d)},remove:function(a,b,c){b.$table.off("click","tr.group-header").off("pagerChange.tsgrouping").find(".group-hidden").removeClass("group-hidden").end().find("tr.group-header").remove()}})}(jQuery); \ No newline at end of file diff --git a/docs/css/jq.css b/docs/css/jq.css index 30fe89a3..f793cc01 100644 --- a/docs/css/jq.css +++ b/docs/css/jq.css @@ -99,7 +99,7 @@ span.alert { padding: 1px 3px; } table th.nobold { font-weight: normal; } table th a { text-decoration: underline; color: #000; } #group .ui-slider,#align .ui-slider { width: 100px; height: 3px; font-size: 0.8em; display: inline-block; margin-left: 10px; } -#group .demo-label,#align .demo-label { display: inline-block; min-width: 120px; } +#group .demo-label,#align .demo-label { display: inline-block; min-width: 125px; } #align .demo-label { display: inline-block; min-width: 150px; } @media all and (max-width: 700px) { table.compatibility, div.box { float: none; width: 100%; margin: 0; } diff --git a/docs/example-widget-grouping.html b/docs/example-widget-grouping.html index 9056a7e0..8d4e0f68 100644 --- a/docs/example-widget-grouping.html +++ b/docs/example-widget-grouping.html @@ -67,6 +67,7 @@ tr.group-header.collapsed td i { +