0

I am trying to export my SAP UI5 table data to csv file using following function,

           table_export = oTable.exportData();
            table_export.saveFile('MY');

also tried,

   oTable.exportData().saveFile('MY');

But I am getting the following error

      Uncaught TypeError: Cannot read property 'indexof' of undefined

Someone could help me with the error

BR- Sathish

  • I guess your error comes from something else, it should work just fine... have you imported the `Export` and `ExportTypeCSV` classes in your page? – Qualiture Mar 10 '15 at 14:58
  • Also, have you specified the `exportType` in the `exportData()` call? See https://openui5.hana.ondemand.com/#docs/guide/f1ee7a8b2102415bb0d34268046cd3ea.html for an example. – qmacro Mar 10 '15 at 15:00
  • Hi Guys, thanks for the reply. Yes i saw the above link and already have the classes included. and i have defined my export type as ExportTypeCSV()... but again i am getting the same error. I found one more link https://openui5beta.hana.ondemand.com/docs/guide/relnotes/ReleaseNotes-1.24.html .. may be its due to version.. but not sure.. . – Sathish Selvaraj Mar 11 '15 at 10:37
  • I have managed to export the files using some available codes using data URI schema functionality, it works fine but in IE 8.. :(.. You guys have any idea .. i am opening another post for this.. – Sathish Selvaraj Mar 11 '15 at 10:38
  • For older browsers, there are some clever hacks. One of them is to create a iFrame programmatically and download the file. – May13ank Jul 23 '15 at 08:59
  • 1
    Pretty sure you are calling "indexof" instead of "indexOf" somewhere in your code. JavaScript is case sensitive. – Chris Neve Apr 11 '16 at 22:16
  • simple answer IE8 is not supported by ui5. you must fetch data by yourself from the model and build some csv file https://stackoverflow.com/questions/3629183/why-doesnt-indexof-work-on-an-array-ie8 – Benedikt Kromer Sep 24 '19 at 14:23

2 Answers2

0

On click off button you can download your table in excel format

new sap.m.Button({
    icon:"sap-icon://download",
    type:"Emphasized",
    press: function(oEvent) {
        debugger;

        jQuery.sap.require("sap.ui.core.util.Export");
        jQuery.sap.require("sap.ui.core.util.ExportTypeCSV");

        oTable.exportData({

        }).saveFile()
        .always(function() {
            this.destroy();
        });

while defining your table columns, mention the below properties too.

sortProperty: "approved_on",
filterProperty: "approved_on"

Note: "approved_on" is the value binded to the respective column.

Floern
  • 33,559
  • 24
  • 104
  • 119
Athul R
  • 1
  • 1
0

The solution is available here how to download data of table into a CSV file. https://sapui5.hana.ondemand.com/#/entity/sap.m.Table/sample/sap.m.sample.TableExport/code/Table.controller.js

You have to Import Export and ExportTypeCSV at the top from the libraries. This works good and I have used the same code in my project app as well. I Hope this is much more simpler.