Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #44 from boonep/master
Browse files Browse the repository at this point in the history
trimWhitespace property and functionality
  • Loading branch information
clarketm authored Jan 21, 2017
2 parents 87824df + e2c6f0f commit d607b53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ $("table").tableExport({
position: "bottom", // (top, bottom), position of the caption element relative to table
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file
ignoreCSS: ".tableexport-ignore" // (selector, selector[]), selector(s) to exclude cells from the exported file
emptyCSS: ".tableexport-empty" // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file
trimWhitespace: false // (Boolean), remove all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of cell text
});
```
> **Note:** to use the xlsx filetype, you must include the third-party scripts listed in the Dependencies section.
Expand Down
25 changes: 19 additions & 6 deletions dist/js/tableexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
}
return new Array(total).concat($(val).text());
}
return $(val).text();
return formatValue($(val).text());
}).get()];
}).get(),
dataObject = TableExport.prototype.escapeHtml(
Expand Down Expand Up @@ -151,7 +151,7 @@
}
return new Array(total).concat($(val).text());
}
return $(val).text();
return formatValue($(val).text());
}).get()];
}).get(),
dataObject = TableExport.prototype.escapeHtml(
Expand Down Expand Up @@ -179,7 +179,7 @@
if ($(val).is(emptyCSS)) {
return " "
}
return $(val).text();
return formatValue($(val).text());
}).get().join(colD);
}).get().join(rdel),
dataObject = TableExport.prototype.escapeHtml(
Expand Down Expand Up @@ -207,7 +207,7 @@
if ($(val).is(emptyCSS)) {
return " "
}
return '"' + $(val).text().replace(/"/g, '""') + '"';
return '"' + formatValue($(val).text().replace(/"/g, '""')) + '"';
}).get().join(colD);
}).get().join(rdel),
dataObject = TableExport.prototype.escapeHtml(
Expand Down Expand Up @@ -235,7 +235,7 @@
if ($(val).is(emptyCSS)) {
return " "
}
return $(val).text();
return formatValue($(val).text());
}).get().join(colD);
}).get().join(rdel),
dataObject = TableExport.prototype.escapeHtml(
Expand All @@ -259,6 +259,18 @@
}
);

function trimWhitespace(string) {
if (self.settings.trimWhitespace) {
return $.trim(string);
}
return string;
}

function formatValue(string) {
string = trimWhitespace(string);
return string;
}

function checkCaption(exportButton) {
var $caption = $el.find('caption:not(.head)');
$caption.length ? $caption.append(exportButton) : $el.prepend('<caption class="' + bootstrapSpacing + self.settings.position + '">' + exportButton + '</caption>');
Expand Down Expand Up @@ -305,7 +317,8 @@
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null)
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file (default: null)
ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file (default: ".tableexport-ignore")
emptyCSS: ".tableexport-empty" // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty")
emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty")
trimWhitespace: false // (Boolean), remove all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of cell text
},
/**
* Character set (character encoding) of the HTML.
Expand Down

0 comments on commit d607b53

Please sign in to comment.