Sencha Grid Exporter fails when exporting to CSV or any other type other than xlsx?

2.3k views Asked by At

I am using Sencha Grid Exporter plugin, while it works perfectly fine when exported to Excel, I cant get it to export to CSV or any other types from my app.

It works fine as listed on the KitchenSink example.

KitchenSink Exporter Example

http://docs.sencha.com/extjs/6.2.1/classic/Ext.grid.plugin.Exporter.html

Ext.getCmp('grid').saveDocumentAs({    
         type: 'csv',  // What other possible values can go here
         title: globals.reportName,
         fileName: 'myExport.csv'
});

Comes with an error as below:

Uncaught Error: [Ext.createByAlias] Unrecognized alias: exporter.CSV
at Ext.Inventory.instantiateByAlias (app.js?_dc=1481916938387:13520)
at Ext.Factory.create (app.js?_dc=1481916938387:23199)
at constructor.getExporter (app.js?_dc=1481916938387:204593)
at constructor.saveDocumentAs (app.js?_dc=1481916938387:204520)
at constructor.saveDocumentAs (app.js?_dc=1481916938387:5355)
at constructor.onMenuitemClick (app.js?_dc=1481916938387:255332)
at constructor.fire (app.js?_dc=1481916938387:19281)
at constructor.doFireEvent (app.js?_dc=1481916938387:20248)
at constructor.doFireEvent (app.js?_dc=1481916938387:65488)
at constructor.prototype.doFireEvent (app.js?_dc=1481916938387:56438)
1

There are 1 answers

5
Alexander On BEST ANSWER

You are missing a requires.

If you tell ExtJS to use type:'csv', it will try to instantiate exporter.csv. If you tell ExtJS to use type:'excel', it will try to instantiate exporter.excel. To get that one from the file system, you have to include the fully qualified name somewhere, e.g. in your requires section:

requires:[
    'Ext.exporter.text.CSV'
]

The heading in the docs has two parts: First the full qualified class name, which is "Ext.exporter.text.CSV", and then, the short name ("exporter.csv"). If you haven't provided the full name anywhere, the file cannot be loaded, unless the framework itself already requires the exporter by full name. Which it, according to the error message, doesn't.

Background info, before you ask "Why doesn't it?": Since the plugin can work with any of the dozens of exporters, and you wouldn't want to load all just to create one type of export, you have to import the exporter manually.