diff --git a/docs/example-widget-output.html b/docs/example-widget-output.html index 10dc8ffe..dfb58286 100644 --- a/docs/example-widget-output.html +++ b/docs/example-widget-output.html @@ -42,7 +42,7 @@ text-align: right; margin-right: 4px; } - div.output-download-popup { + .dropdown-menu li div { margin-bottom: 5px; } .output-separator, .output-replacequotes, .output-quotes { @@ -91,7 +91,7 @@ table.tablesorter tbody tr.even.checked td { // buttons set up like this: // $('button[data-filter-column]').click(function(){ - /*** first method *** data-filter-column="1" data-filter-text="!son" + /*** first method *** data-filter-column="2" data-filter-text="!son" add search value to Discount column (zero based index) input */ var filters = [], $t = $(this), @@ -115,14 +115,16 @@ table.tablesorter tbody tr.even.checked td { headerTemplate : '{content} {icon}', widgets: ["zebra", "filter", "uitheme", "output"], widgetOptions : { - filter_filteredRow : 'filtered', - filter_reset : '.group1 .reset', + filter_filteredRow : 'filtered', + filter_reset : '.group1 .reset', + output_separator : ',', // ',' 'json', 'array' or separator (e.g. ';') - output_ignoreColumns : [0], // columns to ignore [0, 1,... ] (zero-based index) + output_ignoreColumns : [0], // columns to ignore [0, 1,... ] (zero-based index) output_hiddenColumns : false, // include hidden columns in the output output_includeFooter : true, // include footer rows in the output + output_includeHeader : true, // include header rows in the output + output_headerRows : false // output all header rows (if multiple rows) 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, jQuery filter selector (string only) or filter function output_duplicateSpans: true, // duplicate output data in tbody colspan/rowspan @@ -133,7 +135,9 @@ table.tablesorter tbody tr.even.checked td { output_popupStyle : 'width=580,height=310', output_saveFileName : 'mytable.csv', // callbackJSON used when outputting JSON & any header cells has a colspan - unique names required - output_callbackJSON : function($cell, txt, cellIndex) { return txt + '(' + cellIndex + ')'; }, + output_callbackJSON : function($cell, txt, cellIndex) { + return txt + '(' + cellIndex + ')'; + }, // callback executed when processing completes output_callback : function(config, data, url) { // return false to stop delivery & do something else with the data @@ -142,8 +146,13 @@ table.tablesorter tbody tr.even.checked td { }, // the need to modify this for Excel no longer exists - output_encoding : 'data:application/octet-stream;charset=utf8,' - + output_encoding : 'data:application/octet-stream;charset=utf8,', + // override internal save file code and use an external plugin such as + // https://github.com/eligrey/FileSaver.js + output_savePlugin : null /* function(config, widgetOptions, data) { + var blob = new Blob([data], {type: widgetOptions.output_encoding}); + saveAs(blob, widgetOptions.output_saveFileName); + } */ } }).tablesorterPager({ container: $('.ts-pager'), @@ -180,7 +189,7 @@ table.tablesorter tbody tr.even.checked td { // make separator & replace quotes buttons update the value $this.find('.output-separator').click(function(){ $this.find('.output-separator').removeClass('active'); - var txt = $(this).addClass('active').html() + var txt = $(this).addClass('active').html(); $this.find('.output-separator-input').val( txt ); $this.find('.output-filename').val(function(i, v){ // change filename extension based on separator @@ -195,27 +204,42 @@ table.tablesorter tbody tr.even.checked td { $this.find('.output-replacequotes').val( $(this).addClass('active').text() ); return false; }); - + // header/footer toggle buttons + $this.find('.output-header, .output-footer').click(function(){ + $(this).toggleClass('active'); + }); // clicking the download button; all you really need is to // trigger an "output" event on the table $this.find('.download').click(function(){ var typ, $table = $this.find('table'), wo = $table[0].config.widgetOptions, - saved = $this.find('.output-filter-all :checked').attr('class'); - wo.output_separator = $this.find('.output-separator-input').val(); - wo.output_delivery = $this.find('.output-download-popup :checked').attr('class') === 'output-download' ? 'd' : 'p'; - wo.output_saveRows = saved === 'output-filter' ? 'f' : - saved === 'output-visible' ? 'v' : - saved === 'output-selected' ? '.checked' : // checked class name, see table.config.checkboxClass - saved === 'output-sel-vis' ? '.checked:visible' : + val = $this.find('.output-filter-all :checked').attr('class'); + wo.output_saveRows = val === 'output-filter' ? 'f' : + val === 'output-visible' ? 'v' : + // checked class name, see table.config.checkboxClass + val === 'output-selected' ? '.checked' : + val === 'output-sel-vis' ? '.checked:visible' : 'a'; + val = $this.find('.output-download-popup :checked').attr('class'); + wo.output_delivery = val === 'output-download' ? 'd' : 'p'; + wo.output_separator = $this.find('.output-separator-input').val(); wo.output_replaceQuote = $this.find('.output-replacequotes').val(); wo.output_trimSpaces = $this.find('.output-trim').is(':checked'); wo.output_includeHTML = $this.find('.output-html').is(':checked'); wo.output_wrapQuotes = $this.find('.output-wrap').is(':checked'); - wo.output_headerRows = $this.find('.output-headers').is(':checked'); wo.output_saveFileName = $this.find('.output-filename').val(); + + // first example buttons, second has radio buttons + if (groupIndex === 0) { + wo.output_includeHeader = $this.find('button.output-header').is(".active"); + } else { + wo.output_includeHeader = !$this.find('.output-no-header').is(':checked'); + wo.output_headerRows = $this.find('.output-headers').is(':checked'); + } + // footer not included in second example + wo.output_includeFooter = $this.find('.output-footer').is(".active"); + $table.trigger('outputTable'); return false; }); @@ -247,40 +271,55 @@ table.tablesorter tbody tr.even.checked td {
output_callback
now includes a url
parameter.output_saveRows
option to accept a function.output_callback
can return modified data instead of a boolean.output_formatContent
callback function which allows for extra formatting of cell content (e.g. convert '&'
→ '&'
).output_dataAttrib
can now be an empty string.output_saveRows
option, it now includes the ability to set a jQuery filter selector.
+ output_includeHeader
option.output_savePlugin
option.output_callback
now includes a url
parameter.output_saveRows
option to accept a function.output_callback
can return modified data instead of a boolean.output_formatContent
callback function which allows for extra formatting of cell content (e.g. convert '&'
→ '&'
).'.checked'
(default class added by the checkbox parser contained in the "parser-input-select.js" file).'.checked:visible'
.':not(.checked)'
, etc.output_dataAttrib
can now be an empty string.output_saveRows
option, it now includes the ability to set a jQuery filter selector.
+ '.checked'
(default class added by the checkbox parser contained in the "parser-input-select.js" file).'.checked:visible'
.':not(.checked)'
, etc.output_hiddenColumns
causing an empty output.output_hiddenColumns
causing an empty output.output_hiddenColumns
which includes hidden columns in the output when true
.output_includeFooter
option.output_ignoreColumns
option & modified the output_callback
parameters.output_duplicateSpans
option to duplicate (when true
) colspan & rowspan content across cells.output_encoding
option.output_hiddenColumns
which includes hidden columns in the output when true
.output_includeFooter
option.output_ignoreColumns
option & modified the output_callback
parameters.output_duplicateSpans
option to duplicate (when true
) colspan & rowspan content across cells.output_encoding
option."json"
or "array"
, each block of table cell data will be separated by this setting.","
and with the table filtered with Rank :
+ This is the result with this option set to ","
and with the table filtered with Rank :
Rank,First,Last,Age,Total,Discount,Date 111,Peter,Parker,28,$9.99,20%,"Jul 6, 2006 8:14 AM" @@ -516,6 +555,24 @@ line,value1,value2,value3 Change this option totrue
to include the<tfoot>
rows in the output (v2.21.0) ++ +output_includeHeader ++ true
+ Change this option to +false
to not include any rows from the<thead>
in the output (v2.28.4) ++ output_headerRows ++ false
+ Setting this option to +true
will include all header rows while processing a JSON output. +++
+ If this option is set tofalse
, only the last row of the table header will be used as a key names for the tbody values; this does assume that the last table row in the header contains all of the header cell names & does not contain anycolspan
. +- output_dataAttrib @@ -542,17 +599,6 @@ line,value1,value2,value3 'data-name'
- output_headerRows -- false
- Setting this option to -true
will include all header rows while processing a JSON output. ---
- If this option is set tofalse
, only the last row of the table header will be used as a key names for the tbody values; this does assume that the last table row in the header contains all of the header cell names & does not contain anycolspan
. -- output_delivery @@ -685,7 +731,7 @@ line,value1,value2,value3 This option, if 'popup'
true
wrap the output of all table cell content in quotes.
- This is the output of the widget when the age column is filtered for results in the range . + This is the output of the widget when the age column is filtered for results in the range ."Rank","First","Last","Age","Total","Discount","Date" "1","Philip Aaron Wong","Johnson Sr Esq","25","$5.95","22%","Jun 26, 2004 7:22 AM" "111","Peter","Parker","28","$9.99","20%","Jul 6, 2006 8:14 AM" @@ -718,7 +764,6 @@ line,value1,value2,value3'mytable.csv'
When downloading, this option sets the filename of the output. + Note If you need to change the carriage return and/or the tab replacement strings, modify them as follows (changed in v2.21.2): @@ -851,7 +911,7 @@ $.tablesorter.output.replaceTab = '\x09'; output_formatContent null @@ -836,6 +881,21 @@ output_encoding : 'data:text/csv;charset=utf8,' +output_savePlugin ++ null
Override internal save file code and use an external plugin (v2.28.4) + ++
+You can use a plugin such as FileSaver.js instead of the simplified, and possibly out-of-date internal method.
+ Use this option as follows: +output_savePlugin: function(config, widgetOptions, data) { + var blob = new Blob([data], {type: widgetOptions.output_encoding}); + saveAs(blob, widgetOptions.output_saveFileName); +}+