I am having trouble to remove the dollar sign on export as CSV.
I am editing the datatables.min.js file, I know that this is not recommendable but I need this as I have all export on my all modules.
here is the code of the datatables plugin for export button of CSV.
v.ext.buttons.csvHtml5 = {
bom: !1,
className: "buttons-csv buttons-html5",
available: function () {
return g.FileReader !== w && g.Blob;
},
text: function (a) {
return a.i18n("buttons.csv", "CSV");
},
action: function (a, b, d, c) {
this.processing(!0);
a = I(b, c).str;
d = b.buttons.exportInfo(c);
var f = c.charset;
c.customize && (a = c.customize(a, c, b));
!1 !== f
? (f || (f = p.characterSet || p.charset), f && (f = ";charset=" + f))
: (f = "");
c.bom && (a = "" + a);
B(new Blob([a], { type: "text/csv" + f }), d.filename, !0);
this.processing(!1);
},
filename: "*",
extension: ".csv",
exportOptions: {},
fieldSeparator: ",",
fieldBoundary: '"',
escapeChar: '"',
charset: null,
header: !0,
footer: !1,
};
in this code. How can I customize all columns with dollar sign and remove it on export only?
2
Answers
If your data has $ sign you can keep that as only the number.
Then while initializing the datatable make the change to display for the columns which require a $ sign inside render function.
This way since your data will be numerical, export itself will just take the number.
Check this out for Reference
Note: If you can’t change the source data then you can probably process it before giving it to the datatables
If you really want to edit the DataTables source code, I suggest you don’t use
datatables.min.js
. Instead use the un-minified version of the file (datatables.js
). That will be much easier to understand.Having said that, I think this is a really bad idea (as you already seem to know) and I really cannot recommend this approach.
It’s not difficult to do what you want in each DataTable.
Here is one way (not the only way):
In this approach, we use a
columnDefs
option to strip the leading$
from data in theSalary
column:The leading dollar sign is removed using
data.substring(1)
. You can use whatever logic you need there, if this is not exactly what you want.Then, tell the export function to use this modified data:
Even if you need to add this to all of your DataTables now, the time may come when you need a DataTable which does not need this – which is one reason to not attemmpt to edit the source code. (And also you will have a harder time upgrading DataTables if you have edited the source code.)