Skip to content

Commit 40bf880

Browse files
committed
added three new methods (update, reset, remove) and fixed typo in tfoot selector
1 parent 975a5bb commit 40bf880

11 files changed

Lines changed: 83 additions & 24 deletions

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,35 @@ $("table").tableExport({
101101
```
102102
> **Note:** to use the xlsx filetype, you must include the third-party scripts listed in the Dependencies section.
103103
104+
TableExport supports additional methods (**update**, **reset** and **remove**) to control it after creation.
105+
106+
```js
107+
/* Run plugin and save it to a variable */
108+
var tables = $("table").tableExport();
109+
```
110+
111+
```js
112+
/* update */
113+
tables.tableExport.update({
114+
filename: "newFile" // new set of options
115+
})
116+
117+
/* reset */
118+
tables.tableExport.reset(); // this is useful when a table is dyanically alterted after intitialization
119+
120+
/* remove */
121+
table.tableExport.reset();
122+
```
123+
104124
### Properties
105125

106126
A table of available properties and their usage can be found here:
107127
##### [www.clarketravis.com/tableexport](http://www.clarketravis.com/tableexport/#properties)
108128

109129

130+
A table of available properties and their usage can be found here:
131+
##### [www.clarketravis.com/tableexport](http://www.clarketravis.com/tableexport/#properties)
132+
110133

111134
### Settings
112135

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tableexport.js",
3-
"version": "3.2.4",
3+
"version": "3.2.5",
44
"authors": [
55
"clarketm <travis.m.clarke@gmail.com>"
66
],

dist/css/tableexport.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* TableExport.js v3.2.4 (http://www.clarketravis.com)
2+
* TableExport.js v3.2.5 (http://www.clarketravis.com)
33
* Copyright 2016 Travis Clarke
44
* Licensed under the MIT license
55
*/

dist/css/tableexport.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/tableexport.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* TableExport.js v3.2.4 (http://www.clarketravis.com)
2+
* TableExport.js v3.2.5 (http://www.clarketravis.com)
33
* Copyright 2016 Travis Clarke
44
* Licensed under the MIT license
55
*/
@@ -9,9 +9,10 @@
99
/*--- GLOBALS ---*/
1010
var $ = window.jQuery;
1111

12-
$.fn.tableExport = function (options) {
12+
$.fn.tableExport = function (options, isUpdate) {
1313

14-
var settings = $.extend({}, $.fn.tableExport.defaults, options),
14+
var $this = this,
15+
settings = isUpdate ? options : $.extend({}, $.fn.tableExport.defaults, options),
1516
rowD = $.fn.tableExport.rowDel,
1617
ignoreRows = settings.ignoreRows instanceof Array ? settings.ignoreRows : [settings.ignoreRows],
1718
ignoreCols = settings.ignoreCols instanceof Array ? settings.ignoreCols : [settings.ignoreCols],
@@ -27,11 +28,12 @@
2728
bootstrapTheme = bootstrapSpacing = "";
2829
}
2930

30-
this.each(function () {
31-
var $el = $(this),
32-
$rows = $el.find('tbody').find('tr'),
31+
$this.each(function () {
32+
var $el = $(this);
33+
if (isUpdate) { $el.find('caption:not(.head)').remove();}
34+
var $rows = $el.find('tbody').find('tr'),
3335
$rows = settings.headings ? $rows.add($el.find('thead>tr')) : $rows,
34-
$rows = settings.footers ? $rows.add($el.find('tfoor>tr')) : $rows,
36+
$rows = settings.footers ? $rows.add($el.find('tfoot>tr')) : $rows,
3537
thAdj = settings.headings ? $el.find('thead>tr').length : 0,
3638
fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName,
3739
exporters = {
@@ -147,6 +149,22 @@
147149
fileExtension = object.fileExtension;
148150
export2file(data, mimeType, fileName, fileExtension);
149151
});
152+
153+
$.fn.tableExport.update = function (options) {
154+
$this.tableExport($.extend({}, settings, options), true)
155+
};
156+
157+
$.fn.tableExport.reset = function (options) {
158+
$this.tableExport(settings, true)
159+
};
160+
161+
$.fn.tableExport.remove = function (options) {
162+
$this.each(function () {
163+
$(this).find('caption:not(.head)').remove();
164+
});
165+
};
166+
167+
return $this;
150168
};
151169

152170
// Define the plugin default properties.

dist/js/tableexport.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tableexport",
3-
"version": "3.2.4",
3+
"version": "3.2.5",
44
"authors": [
55
"clarketm <travis.m.clarke@gmail.com>"
66
],

src/stable/css/tableexport.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* TableExport.js v3.2.4 (http://www.clarketravis.com)
2+
* TableExport.js v3.2.5 (http://www.clarketravis.com)
33
* Copyright 2016 Travis Clarke
44
* Licensed under the MIT license
55
*/

src/stable/css/tableexport.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/stable/js/tableexport.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* TableExport.js v3.2.4 (http://www.clarketravis.com)
2+
* TableExport.js v3.2.5 (http://www.clarketravis.com)
33
* Copyright 2016 Travis Clarke
44
* Licensed under the MIT license
55
*/
@@ -9,9 +9,10 @@
99
/*--- GLOBALS ---*/
1010
var $ = window.jQuery;
1111

12-
$.fn.tableExport = function (options) {
12+
$.fn.tableExport = function (options, isUpdate) {
1313

14-
var settings = $.extend({}, $.fn.tableExport.defaults, options),
14+
var $this = this,
15+
settings = isUpdate ? options : $.extend({}, $.fn.tableExport.defaults, options),
1516
rowD = $.fn.tableExport.rowDel,
1617
ignoreRows = settings.ignoreRows instanceof Array ? settings.ignoreRows : [settings.ignoreRows],
1718
ignoreCols = settings.ignoreCols instanceof Array ? settings.ignoreCols : [settings.ignoreCols],
@@ -27,11 +28,12 @@
2728
bootstrapTheme = bootstrapSpacing = "";
2829
}
2930

30-
this.each(function () {
31-
var $el = $(this),
32-
$rows = $el.find('tbody').find('tr'),
31+
$this.each(function () {
32+
var $el = $(this);
33+
if (isUpdate) { $el.find('caption:not(.head)').remove();}
34+
var $rows = $el.find('tbody').find('tr'),
3335
$rows = settings.headings ? $rows.add($el.find('thead>tr')) : $rows,
34-
$rows = settings.footers ? $rows.add($el.find('tfoor>tr')) : $rows,
36+
$rows = settings.footers ? $rows.add($el.find('tfoot>tr')) : $rows,
3537
thAdj = settings.headings ? $el.find('thead>tr').length : 0,
3638
fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName,
3739
exporters = {
@@ -147,6 +149,22 @@
147149
fileExtension = object.fileExtension;
148150
export2file(data, mimeType, fileName, fileExtension);
149151
});
152+
153+
$.fn.tableExport.update = function (options) {
154+
$this.tableExport($.extend({}, settings, options), true)
155+
};
156+
157+
$.fn.tableExport.reset = function (options) {
158+
$this.tableExport(settings, true)
159+
};
160+
161+
$.fn.tableExport.remove = function (options) {
162+
$this.each(function () {
163+
$(this).find('caption:not(.head)').remove();
164+
});
165+
};
166+
167+
return $this;
150168
};
151169

152170
// Define the plugin default properties.

0 commit comments

Comments
 (0)