forked from edspencer/Ext.ux.Exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exporter.js
49 lines (40 loc) · 1.4 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
/**
* @class Ext.ux.Exporter
* @author Ed Spencer (http://edspencer.net)
* Class providing a common way of downloading data in .xls or .csv format
*/
Ext.ux.Exporter = function() {
return {
/**
* Exports a grid, using the .xls formatter by default
* @param {Ext.grid.GridPanel} grid The grid to export from
* @param {Object} config Optional config settings for the formatter
*/
exportGrid: function(grid, formatter, config) {
config = config || {};
formatter = formatter || new Ext.ux.Exporter.ExcelFormatter();
Ext.applyIf(config, {
title : grid.title,
columns: grid.getColumnModel().config
});
return Base64.encode(formatter.format(grid.store, config));
},
exportStore: function(store, formatter, config) {
config = config || {};
formatter = formatter || new Ext.ux.Exporter.ExcelFormatter();
Ext.applyIf(config, {
columns: config.store.fields.items
});
return Base64.encode(formatter.format(store, config));
},
exportTree: function(tree, formatter, config) {
config = config || {};
formatter = formatter || new Ext.ux.Exporter.ExcelFormatter();
var store = tree.store || config.store;
Ext.applyIf(config, {
title: tree.title
});
return Base64.encode(formatter.format(store, config));
}
};
}();