diff --git a/dist/js/widgets/widget-output.min.js b/dist/js/widgets/widget-output.min.js index f44f0bb0..fd9871dd 100644 --- a/dist/js/widgets/widget-output.min.js +++ b/dist/js/widgets/widget-output.min.js @@ -1,2 +1,2 @@ /*! Widget: output - updated 1/10/2016 (v2.25.1) */ -!function(a){"use strict";var b=a.tablesorter,c=b.output={event:"outputTable",regexQuote:/([\n\t\x09\x0d\x0a]|<[^<]+>)/,regexBR:/(|\n)/g,regexIMG:/]+alt\s*=\s*['"]([^'"]+)['"][^>]*>/i,regexHTML:/<[^<]+>/g,replaceCR:"\r\n",replaceTab:" ",popupTitle:"Output",popupStyle:"width:100%;height:100%;",message:"Your device does not support downloading. Please try again in desktop browser.",init:function(a){a.$table.off(c.event).on(c.event,function(b){b.stopPropagation(),c.process(a,a.widgetOptions)})},processRow:function(d,e,f,g){var h,i,j,k,l,m,n,o,p,q,r=d.widgetOptions,s=[],t=r.output_duplicateSpans,u=f&&g&&r.output_headerRows&&a.isFunction(r.output_callbackJSON),v=0,w=e.length;for(k=0;w>k;k++)for(s[k]||(s[k]=[]),v=0,i=e.eq(k).children(),j=i.length,n=0;j>n;n++){if(h=i.eq(n),h.filter("[rowspan]").length)for(o=parseInt(h.attr("rowspan"),10)-1,q=c.formatData(d,r,h,f),l=1;o>=l;l++)s[k+l]||(s[k+l]=[]),s[k+l][v]=f?q:t?q:"";if(h.filter("[colspan]").length)for(p=parseInt(h.attr("colspan"),10)-1,q=c.formatData(d,r,h,f),m=1;p>=m;m++)if(h.filter("[rowspan]").length)for(o=parseInt(h.attr("rowspan"),10),l=0;o>l;l++)s[k+l]||(s[k+l]=[]),s[k+l][v+m]=u?r.output_callbackJSON(h,q,v+m)||q+"("+(v+m)+")":f?q:t?q:"";else s[k][v+m]=u?r.output_callbackJSON(h,q,v+m)||q+"("+(v+m)+")":f?q:t?q:"";for(;"undefined"!=typeof s[k][v];)v++;s[k][v]=s[k][v]||c.formatData(d,r,h,f),v++}return b.output.removeColumns(d,r,s)},removeColumns:function(a,b,c){var d,e,f,g=[],h=c.length;for(d=0;h>d;d++)for(e=c[d],g[d]=[],f=0;f-1||!e.output_hiddenColumns&&"none"===d.$headerIndexed[o].css("display")&&!d.$headerIndexed[o].hasClass("tablesorter-scroller-hidden-column");if(g=u.children("thead").children("tr").not("."+(b.css.filterRow||"tablesorter-filter-row")).filter(function(){return e.output_hiddenColumns||"none"!==a(this).css("display")}),i=c.processRow(d,g,!0,q),h=u.children("tbody").children("tr"),h=/^f/.test(t)?h.not("."+(e.filter_filteredRow||"filtered")):/^v/.test(t)?h.filter(":visible"):/^[.#:\[]/.test(t)?h.filter(t):h,j=c.processRow(d,h),e.output_includeFooter&&(j=j.concat(c.processRow(d,u.children("tfoot").children("tr:visible")))),k=i.length,q){for(p=[],l=j.length,o=0;l>o;o++)m=i[k>1&&e.output_headerRows?o%k:k-1],p.push(c.row2Hash(m,j[o]));f=n?JSON.stringify(p):p}else m=[i[k>1&&e.output_headerRows?o%k:k-1]],p=c.row2CSV(e,e.output_headerRows?i:m,r).concat(c.row2CSV(e,j,r)),f=r&&n?JSON.stringify(p):p.join("\n");if(a.isFunction(e.output_callback)){if(m=e.output_callback(d,f),m===!1)return;"string"==typeof m&&(f=m)}/p/i.test(e.output_delivery||"")?c.popup(f,e.output_popupStyle,q||r):c.download(e,f)},row2CSV:function(a,b,c){var d,e,f=[],g=b.length;for(e=0;g>e;e++)d=(b[e]||[]).join("").replace(/\"/g,""),(b[e]||[]).length>0&&""!==d&&(f[f.length]=c?b[e]:b[e].join(a.output_separator));return f},row2Hash:function(a,b){var c,d={},e=b.length;for(c=0;e>c;c++)c"+c.popupTitle+'"),e.document.close(),e.focus(),!0},download:function(a,b){var d,e,f,g=window.navigator,h=document.createElement("a");if(/(iP)/g.test(g.userAgent))return alert(c.message),!1;try{f=!!new Blob}catch(i){f=!1}return f?(window.URL=window.URL||window.webkitURL,e=new Blob(["\ufeff",b],{type:a.output_encoding}),g.msSaveBlob?g.msSaveBlob(e,a.output_saveFileName):(h.href=window.URL.createObjectURL(e),h.download=a.output_saveFileName,document.createEvent&&(d=document.createEvent("MouseEvents"),d.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),h.dispatchEvent(d))),!1):(window.open(a.output_encoding+encodeURIComponent(b)+"?download","_self"),!0)},remove:function(a){a.$table.off(c.event)}};b.addWidget({id:"output",options:{output_separator:",",output_ignoreColumns:[],output_hiddenColumns:!1,output_includeFooter:!1,output_dataAttrib:"data-name",output_headerRows:!1,output_delivery:"popup",output_saveRows:"filtered",output_duplicateSpans:!0,output_replaceQuote:"“;",output_includeHTML:!1,output_trimSpaces:!0,output_wrapQuotes:!1,output_popupStyle:"width=500,height=300",output_saveFileName:"mytable.csv",output_formatContent:null,output_callback:function(a,b){return!0},output_callbackJSON:function(a,b,c){return b+"("+c+")"},output_encoding:"data:application/octet-stream;charset=utf8,"},init:function(a,b,d){c.init(d)},remove:function(a,b){c.remove(b)}})}(jQuery); \ No newline at end of file +!function(a){"use strict";var b=a.tablesorter,c=b.output={event:"outputTable",regexQuote:/([\n\t\x09\x0d\x0a]|<[^<]+>)/,regexBR:/(|\n)/g,regexIMG:/]+alt\s*=\s*['"]([^'"]+)['"][^>]*>/i,regexHTML:/<[^<]+>/g,replaceCR:"\r\n",replaceTab:" ",popupTitle:"Output",popupStyle:"width:100%;height:100%;",message:"Your device does not support downloading. Please try again in desktop browser.",init:function(a){a.$table.off(c.event).on(c.event,function(b){b.stopPropagation(),c.process(a,a.widgetOptions)})},processRow:function(d,e,f,g){var h,i,j,k,l,m,n,o,p,q,r=d.widgetOptions,s=[],t=r.output_duplicateSpans,u=f&&g&&r.output_headerRows&&a.isFunction(r.output_callbackJSON),v=0,w=e.length;for(k=0;w>k;k++)for(s[k]||(s[k]=[]),v=0,i=e.eq(k).children(),j=i.length,n=0;j>n;n++){if(h=i.eq(n),h.filter("[rowspan]").length)for(o=parseInt(h.attr("rowspan"),10)-1,q=c.formatData(d,r,h,f),l=1;o>=l;l++)s[k+l]||(s[k+l]=[]),s[k+l][v]=f?q:t?q:"";if(h.filter("[colspan]").length)for(p=parseInt(h.attr("colspan"),10)-1,q=c.formatData(d,r,h,f),m=1;p>=m;m++)if(h.filter("[rowspan]").length)for(o=parseInt(h.attr("rowspan"),10),l=0;o>l;l++)s[k+l]||(s[k+l]=[]),s[k+l][v+m]=u?r.output_callbackJSON(h,q,v+m)||q+"("+(v+m)+")":f?q:t?q:"";else s[k][v+m]=u?r.output_callbackJSON(h,q,v+m)||q+"("+(v+m)+")":f?q:t?q:"";for(;"undefined"!=typeof s[k][v];)v++;s[k][v]=s[k][v]||c.formatData(d,r,h,f),v++}return b.output.removeColumns(d,r,s)},removeColumns:function(a,b,c){var d,e,f,g=[],h=c.length;for(d=0;h>d;d++)for(e=c[d],g[d]=[],f=0;f-1||!e.output_hiddenColumns&&"none"===d.$headerIndexed[o].css("display")&&!d.$headerIndexed[o].hasClass("tablesorter-scroller-hidden-column");if(g=u.children("thead").children("tr").not("."+(b.css.filterRow||"tablesorter-filter-row")).filter(function(){return e.output_hiddenColumns||"none"!==a(this).css("display")}),i=c.processRow(d,g,!0,q),h=u.children("tbody").children("tr"),h="function"==typeof t?h.filter(t):/^f/.test(t)?h.not("."+(e.filter_filteredRow||"filtered")):/^v/.test(t)?h.filter(":visible"):/^[.#:\[]/.test(t)?h.filter(t):h,j=c.processRow(d,h),e.output_includeFooter&&(j=j.concat(c.processRow(d,u.children("tfoot").children("tr:visible")))),k=i.length,q){for(p=[],l=j.length,o=0;l>o;o++)m=i[k>1&&e.output_headerRows?o%k:k-1],p.push(c.row2Hash(m,j[o]));f=n?JSON.stringify(p):p}else m=[i[k>1&&e.output_headerRows?o%k:k-1]],p=c.row2CSV(e,e.output_headerRows?i:m,r).concat(c.row2CSV(e,j,r)),f=r&&n?JSON.stringify(p):p.join("\n");if(a.isFunction(e.output_callback)){if(m=e.output_callback(d,f),m===!1)return;"string"==typeof m&&(f=m)}/p/i.test(e.output_delivery||"")?c.popup(f,e.output_popupStyle,q||r):c.download(e,f)},row2CSV:function(a,b,c){var d,e,f=[],g=b.length;for(e=0;g>e;e++)d=(b[e]||[]).join("").replace(/\"/g,""),(b[e]||[]).length>0&&""!==d&&(f[f.length]=c?b[e]:b[e].join(a.output_separator));return f},row2Hash:function(a,b){var c,d={},e=b.length;for(c=0;e>c;c++)c"+c.popupTitle+'"),e.document.close(),e.focus(),!0},download:function(a,b){var d,e,f,g=window.navigator,h=document.createElement("a");if(/(iP)/g.test(g.userAgent))return alert(c.message),!1;try{f=!!new Blob}catch(i){f=!1}return f?(window.URL=window.URL||window.webkitURL,e=new Blob(["\ufeff",b],{type:a.output_encoding}),g.msSaveBlob?g.msSaveBlob(e,a.output_saveFileName):(h.href=window.URL.createObjectURL(e),h.download=a.output_saveFileName,document.createEvent&&(d=document.createEvent("MouseEvents"),d.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),h.dispatchEvent(d))),!1):(window.open(a.output_encoding+encodeURIComponent(b)+"?download","_self"),!0)},remove:function(a){a.$table.off(c.event)}};b.addWidget({id:"output",options:{output_separator:",",output_ignoreColumns:[],output_hiddenColumns:!1,output_includeFooter:!1,output_dataAttrib:"data-name",output_headerRows:!1,output_delivery:"popup",output_saveRows:"filtered",output_duplicateSpans:!0,output_replaceQuote:"“;",output_includeHTML:!1,output_trimSpaces:!0,output_wrapQuotes:!1,output_popupStyle:"width=500,height=300",output_saveFileName:"mytable.csv",output_formatContent:null,output_callback:function(a,b){return!0},output_callbackJSON:function(a,b,c){return b+"("+c+")"},output_encoding:"data:application/octet-stream;charset=utf8,"},init:function(a,b,d){c.init(d)},remove:function(a,b){c.remove(b)}})}(jQuery); \ No newline at end of file diff --git a/docs/example-widget-output.html b/docs/example-widget-output.html index e09141dd..09144375 100644 --- a/docs/example-widget-output.html +++ b/docs/example-widget-output.html @@ -124,7 +124,7 @@ table.tablesorter tbody tr.even.checked td { output_dataAttrib : 'data-name', // data-attribute containing alternate cell text output_headerRows : true, // output all header rows (multiple rows) output_delivery : 'p', // (p)opup, (d)ownload - output_saveRows : 'f', // (a)ll, (v)isible, (f)iltered or jQuery filter selector (string only) + output_saveRows : 'f', // (a)ll, (v)isible, (f)iltered, jQuery filter selector (string only) or filter function output_duplicateSpans: true, // duplicate output data in tbody colspan/rowspan output_replaceQuote : '\u201c;', // change quote to left double quote output_includeHTML : true, // output includes all cell HTML (except the header cells) @@ -247,6 +247,7 @@ table.tablesorter tbody tr.even.checked td {

Changes

    +
  • In v2.25.2, updated the output_saveRows option to accept a function.
  • In v2.25.1, the output_callback can return modified data instead of a boolean.
  • In v2.22.4, added output_formatContent callback function which allows for extra formatting of cell content (e.g. convert '&amp;''&').
  • In v2.22.2, @@ -568,7 +569,7 @@ line,value1,value2,value3 'filtered' - Change this option to either 'filtered', 'visible', 'all' or (v2.22.2) a jQuery filter selector to set to match rows to be added to the output. + Change this option to either 'filtered', 'visible', 'all', a jQuery filter selector (v2.25.1) to set to match rows to be added to the output, or a jQuery filter callback function (v2.25.2).

      @@ -589,6 +590,12 @@ line,value1,value2,value3
  • 'all' - output all rows even if they are hidden. When the pager removeRows option is true, rows not visible do not exist in the DOM and therefore will not be included.
  • +
  • function - (v2.25.2) Include a filter function to test each row and return a boolean value; true to include the row, and false to exclude. For example: +
    output_saveRows: function(index, element) {
    +  // "this" is the same as "element"
    +  // only include the row if the select element's value is set to "include".
    +  return $(this).find('select').val() === 'include';
    +}

Even if this option is set to 'filtered' and the filter widget is not being used, all of the rows will be added to the output.

*NOTE* When setting this option,

@@ -596,7 +603,7 @@ line,value1,value2,value3
  • Only the first letter is required for filtered ('f') or visible ('v') rows.
    output_saveRows : 'f'
  • -
  • If using a jQuery selector, it won't be recognized as a selector unless one of the characters (.#:[) is contained in the setting; if your filter is not working, or uses a charater not listed, then please contact me for support.
  • +
  • If using a jQuery selector, it won't be recognized as a selector unless one of the characters (.#:[) is at the start of the string; if your filter is not working, or uses a charater not listed, then use the callback function, or you can contact me for support.
  • If no matches are found, all rows will be sent to the output.
  • diff --git a/js/widgets/widget-output.js b/js/widgets/widget-output.js index d5c231c9..e0243f32 100644 --- a/js/widgets/widget-output.js +++ b/js/widgets/widget-output.js @@ -148,8 +148,11 @@ // all tbody rows $rows = $el.children('tbody').children('tr'); - // get (f)iltered, (v)isible, all rows (look for the first letter only), or jQuery filter selector - $rows = /^f/.test(saveRows) ? $rows.not('.' + (wo.filter_filteredRow || 'filtered') ) : + // check for a filter callback function first! because + // /^f/.test(function(){ console.log('test'); }) is TRUE! (function is converted to a string) + $rows = typeof saveRows === 'function' ? $rows.filter(saveRows) : + // get (f)iltered, (v)isible, all rows (look for the first letter only), or jQuery filter selector + /^f/.test(saveRows) ? $rows.not('.' + (wo.filter_filteredRow || 'filtered') ) : /^v/.test(saveRows) ? $rows.filter(':visible') : // look for '.' (class selector), '#' (id selector), // ':' (basic filters, e.g. ':not()') or '[' (attribute selector start)