forked from iwiznia/Ext.ux.Exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExporter.js
66 lines (60 loc) · 2.33 KB
/
Exporter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @class Ext.ux.Exporter
* @author Ed Spencer (http://edspencer.net), with modifications from iwiznia.
* Class providing a common way of downloading data in .xls or .csv format
*/
Ext.define("Ext.ux.exporter.Exporter", {
uses: [
"Ext.ux.exporter.Base64",
"Ext.ux.exporter.csvFormatter.CsvFormatter",
"Ext.ux.exporter.excelFormatter.ExcelFormatter"
],
statics: {
exportAny: function(component, formatter, title) {
var func = "export";
if(!component.is) {
func = func + "Store";
} else if(component.is("gridpanel")) {
func = func + "Grid";
} else if (component.is("treepanel")) {
func = func + "Tree";
} else {
func = func + "Store";
component = component.getStore();
}
return this[func](component, formatter, title);
},
exportGrid: function(grid, formatter, title) {
formatter = this.getFormatterByName(formatter);
var columns = Ext.Array.filter(grid.columns, function(col) {
return !col.hidden && (!col.xtype || col.xtype != "actioncolumn");
});
var config = {
title: grid.title ? grid.title : title,
columns: columns
};
return formatter.format(grid.store, config);
},
exportStore: function(store, formatter, title) {
formatter = this.getFormatterByName(formatter);
var config = {
title: title,
columns: store.fields ? store.fields.items : store.model.prototype.fields.items
}
return formatter.format(store, config);
},
exportTree: function(tree, formatter, title) {
formatter = this.getFormatterByName(formatter);
var store = tree.store;
var config = {
title: tree.title ? tree.title : title
}
return formatter.format(store, config);
},
getFormatterByName: function(formatter) {
formatter = formatter ? formatter : "excel";
formatter = !Ext.isString(formatter) ? formatter : Ext.create("Ext.ux.exporter." + formatter + "Formatter." + Ext.String.capitalize(formatter) + "Formatter");
return formatter;
}
}
});