Skip to content

Commit d607b53

Browse files
authored
Merge pull request clarketm#44 from boonep/master
trimWhitespace property and functionality
2 parents 87824df + e2c6f0f commit d607b53

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ $("table").tableExport({
112112
position: "bottom", // (top, bottom), position of the caption element relative to table
113113
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file
114114
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file
115-
ignoreCSS: ".tableexport-ignore" // (selector, selector[]), selector(s) to exclude cells from the exported file
116-
emptyCSS: ".tableexport-empty" // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file
115+
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file
116+
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file
117+
trimWhitespace: false // (Boolean), remove all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of cell text
117118
});
118119
```
119120
> **Note:** to use the xlsx filetype, you must include the third-party scripts listed in the Dependencies section.

dist/js/tableexport.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
}
101101
return new Array(total).concat($(val).text());
102102
}
103-
return $(val).text();
103+
return formatValue($(val).text());
104104
}).get()];
105105
}).get(),
106106
dataObject = TableExport.prototype.escapeHtml(
@@ -151,7 +151,7 @@
151151
}
152152
return new Array(total).concat($(val).text());
153153
}
154-
return $(val).text();
154+
return formatValue($(val).text());
155155
}).get()];
156156
}).get(),
157157
dataObject = TableExport.prototype.escapeHtml(
@@ -179,7 +179,7 @@
179179
if ($(val).is(emptyCSS)) {
180180
return " "
181181
}
182-
return $(val).text();
182+
return formatValue($(val).text());
183183
}).get().join(colD);
184184
}).get().join(rdel),
185185
dataObject = TableExport.prototype.escapeHtml(
@@ -207,7 +207,7 @@
207207
if ($(val).is(emptyCSS)) {
208208
return " "
209209
}
210-
return '"' + $(val).text().replace(/"/g, '""') + '"';
210+
return '"' + formatValue($(val).text().replace(/"/g, '""')) + '"';
211211
}).get().join(colD);
212212
}).get().join(rdel),
213213
dataObject = TableExport.prototype.escapeHtml(
@@ -235,7 +235,7 @@
235235
if ($(val).is(emptyCSS)) {
236236
return " "
237237
}
238-
return $(val).text();
238+
return formatValue($(val).text());
239239
}).get().join(colD);
240240
}).get().join(rdel),
241241
dataObject = TableExport.prototype.escapeHtml(
@@ -259,6 +259,18 @@
259259
}
260260
);
261261

262+
function trimWhitespace(string) {
263+
if (self.settings.trimWhitespace) {
264+
return $.trim(string);
265+
}
266+
return string;
267+
}
268+
269+
function formatValue(string) {
270+
string = trimWhitespace(string);
271+
return string;
272+
}
273+
262274
function checkCaption(exportButton) {
263275
var $caption = $el.find('caption:not(.head)');
264276
$caption.length ? $caption.append(exportButton) : $el.prepend('<caption class="' + bootstrapSpacing + self.settings.position + '">' + exportButton + '</caption>');
@@ -305,7 +317,8 @@
305317
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null)
306318
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file (default: null)
307319
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file (default: ".tableexport-ignore")
308-
emptyCSS: ".tableexport-empty" // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty")
320+
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty")
321+
trimWhitespace: false // (Boolean), remove all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of cell text
309322
},
310323
/**
311324
* Character set (character encoding) of the HTML.

0 commit comments

Comments
 (0)