Reputation: 31
I'm learning OpenUI5 as part as my new job/internship and I've hit a snag in the product that I'm working on. The exported csv is correct as far as everything that we want is properly exported but if the string/input of an item contains a new line character or is ended with the enter key it breaks the csv export but the model within the table still displays correctly.
description.replace(/(\r\n|\n|\r)/gm," ");
Is what would work to remove any line returns or enters being found within the string but the way that data is bound within this application is within this type of structure:
exportType : new sap.ui.core.util.ExportTypeCSV({
separatorChar : "," //;
}),
models : table.getModel(),
rows : {
path : "/interactions"
},
columns : [ {
name : "description",
template : {
content : "{description}"
}
}] // There is more listings after this but it's not important
// ... more items here
}); // End of the bounded data to export
As stated previously, my item 'description' can contain new line characters but when I convert to to csv in the export, it will do something like this:
90000440,Information Protection Policy,Scene1_QuestionDraw01_Slide1_TrueFalse_0_0,The Information Security Officer is responsible for the review and revision of this policy.
(True or False),false,false,1,1
There isn't supposed to be an actual line return within the outputted csv but since there is a new line character or line return within the description, it outputs one in the export.
Any amount of help that leads to me solving this issue would be fantastic.
Thank you, Jordan.
Upvotes: 3
Views: 596
Reputation: 5206
The best way would be to be able to use string delimiters as indicated in the comment by criticalfix. This normally works by default, see the following code from the current UI5 codebase: github. It might be that you have an UI5 version that does not cover this, because this was fixed last year in summer (see this commit). You can see the versions which contain this commit in the commit itself (immediately above the author line).
If you cannot upgrade to a version that contains this commit, then maybe your first idea of replacing the newlines would be appropriate. You can use a formatter in conjunction with your binding to remove the newlines:
// all the stuff before
columns : [ {
name : "description",
template : {
content : {
path: "description",
formatter: function (description) {
return description.replace(/(\r\n|\n|\r)/gm," ");
}
}
}
}]
Upvotes: 1