Remove unwanted lines / breaks in csv export in openUI5

I am learning OpenUI5 as part of my new job / internship and I have fallen into the trap of the product I am working on. The exported csv is correct as everything we want is exported correctly, but if the line / input of the element contains a new line character or ends with the enter key, it aborts the csv export, but the model in the table is still displayed correctly.

description.replace(/(\r\n|\n|\r)/gm," ");

      

This is what will work to delete any row or enter it, but the way the data is related in this application is inside this type of struct:

    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 not important
 // ... more items here
            }); // End of the bounded data to export 

      

As stated earlier, my item description may contain new string characters, but when I convert to csv to 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

      

The csv output shouldn't actually return a line, but since there is a new line or line character in the description, it outputs one of them to export.

Any help that leads me to solve this problem would be fantastic.

Thank you, Jordan.

+3


source to share


1 answer


The best way would be to use line delimiters as pointed out in the comment critically. This usually works by default, see the following code from the current UI5 codebase: github . Perhaps you have a UI5 version that doesn't cover this because it was fixed last year in the summer (see this commit ). You can see the versions that contain this commit in the commit itself (just above the author line).

If you are unable to upgrade to a version that contains this commit, your first idea of ​​replacing newlines might be appropriate. You can use a formatter in conjunction with your binding to remove newlines:



// all the stuff before
columns : [  {
    name : "description",
        template : {
            content : {
                 path: "description",
                 formatter: function (description) {
                     return description.replace(/(\r\n|\n|\r)/gm," ");
                 }
            }
        }
}]

      

0


source







All Articles