Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In the Exporter-all.js, implement downloadify as shown below
- Ext.ux.Exporter.Button = Ext.extend(Ext.Button, {
- constructor: function (config) {
- config = config || {};
- Ext.applyIf(config, {
- exportFunction: 'exportStore',
- disabled: true//,
- //text: 'Download',
- //cls: 'download'
- });
- if (config.store == undefined && config.component != undefined) {
- Ext.applyIf(config, {
- store: config.component.store
- });
- }
- else {
- Ext.applyIf(config, {
- component: {
- store: config.store
- }
- });
- }
- Ext.ux.Exporter.Button.superclass.constructor.call(this, config);
- if (this.store && Ext.isFunction(this.store.on)) {
- this.getEl().child('a', true).href = "javascript:void(0)"; //'data:application/vnd.ms-excel;base64,' + Ext.ux.Exporter[config.exportFunction](this.component, null, config);
- var setLink = function () {
- debugger;
- Downloadify.create(this.btnEl, {
- onComplete: function () {
- alert('Your spreadsheet has been saved.');
- },
- onCancel: function () {
- alert('You have cancelled the saving of this file.');
- },
- onError: function () {
- alert('You must put something in the File Contents or there will be nothing to export!');
- },
- filename: 'export.xls',
- data: Ext.ux.Exporter[config.exportFunction](this.component, null, config),
- swf: '../ProjectResources/scripts/Downloadify/media/downloadify.swf',
- downloadImage: '../ProjectResources/scripts/Downloadify/images/download.png',
- dataType: 'base64',
- width: 100,
- height: 30,
- transparent: true,
- append: true
- });
- this.enable();
- };
- if (this.el) {
- setLink.call(this);
- } else {
- this.on('render', setLink, this);
- }
- this.store.on('load', setLink, this);
- }
- },
- template: new Ext.Template(
- '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
- '<td class="x-btn-left"><i> </i></td><td class="x-btn-center"><a class="x-btn-text" href="{1}" target="{2}">{0}</a></td><td class="x-btn-right"><i> </i></td>',
- "</tr></tbody></table>"),
- onRender: function (ct, position) {
- var btn, targs = [this.text || ' ', this.href, this.target || "_self"];
- if (position) {
- btn = this.template.insertBefore(position, targs, true);
- } else {
- btn = this.template.append(ct, targs, true);
- }
- var btnEl = btn.child("a:first");
- this.btnEl = btnEl;
- btnEl.on('focus', this.onFocus, this);
- btnEl.on('blur', this.onBlur, this);
- this.initButtonEl(btn, btnEl);
- Ext.ButtonToggleMgr.register(this);
- },
- onClick: function (e) {
- if (e.button != 0) return;
- if (!this.disabled) {
- this.fireEvent("click", this, e);
- if (this.handler) this.handler.call(this.scope || this, this, e);
- }
- }
- });
- Ext.reg('exportbutton', Ext.ux.Exporter.Button);
- //In your main script, create the exporter button as below
- var exportButton = new Ext.ux.Exporter.Button({
- component: _grid,
- store: someStore, // the store you want to export
- id: 'exportButton',
- renderTo: 'btn-div' // render to a div in your page, but this is not necessary, it applies if you have the button separately from the grid
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement