Advertisement
Guest User

Ext.ux.Exporter and Downloadify

a guest
Aug 17th, 2010
1,115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // In the Exporter-all.js, implement downloadify as shown below
  2.  
  3. Ext.ux.Exporter.Button = Ext.extend(Ext.Button, {
  4.     constructor: function (config) {
  5.         config = config || {};
  6.  
  7.         Ext.applyIf(config, {
  8.             exportFunction: 'exportStore',
  9.             disabled: true//,
  10.             //text: 'Download',
  11.             //cls: 'download'
  12.         });
  13.  
  14.         if (config.store == undefined && config.component != undefined) {
  15.             Ext.applyIf(config, {
  16.                 store: config.component.store
  17.             });
  18.         }
  19.         else {
  20.             Ext.applyIf(config, {
  21.                 component: {
  22.                     store: config.store
  23.                 }
  24.             });
  25.         }
  26.  
  27.         Ext.ux.Exporter.Button.superclass.constructor.call(this, config);
  28.  
  29.         if (this.store && Ext.isFunction(this.store.on)) {
  30.  
  31.             this.getEl().child('a', true).href = "javascript:void(0)"; //'data:application/vnd.ms-excel;base64,' + Ext.ux.Exporter[config.exportFunction](this.component, null, config);
  32.  
  33.             var setLink = function () {
  34.                 debugger;
  35.                 Downloadify.create(this.btnEl, {
  36.                     onComplete: function () {
  37.                         alert('Your spreadsheet has been saved.');
  38.                     },
  39.                     onCancel: function () {
  40.                         alert('You have cancelled the saving of this file.');
  41.                     },
  42.                     onError: function () {
  43.                         alert('You must put something in the File Contents or there will be nothing to export!');
  44.                     },
  45.                     filename: 'export.xls',
  46.                     data: Ext.ux.Exporter[config.exportFunction](this.component, null, config),
  47.                     swf: '../ProjectResources/scripts/Downloadify/media/downloadify.swf',
  48.                     downloadImage: '../ProjectResources/scripts/Downloadify/images/download.png',
  49.                     dataType: 'base64',
  50.                     width: 100,
  51.                     height: 30,
  52.  
  53.                     transparent: true,
  54.                     append: true
  55.                 });
  56.  
  57.                
  58.                 this.enable();
  59.             };
  60.  
  61.             if (this.el) {
  62.                 setLink.call(this);
  63.             } else {
  64.                 this.on('render', setLink, this);
  65.             }
  66.  
  67.             this.store.on('load', setLink, this);
  68.         }
  69.     },
  70.  
  71.     template: new Ext.Template(
  72.     '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
  73.     '<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>',
  74.     "</tr></tbody></table>"),
  75.  
  76.     onRender: function (ct, position) {
  77.         var btn, targs = [this.text || ' ', this.href, this.target || "_self"];
  78.         if (position) {
  79.             btn = this.template.insertBefore(position, targs, true);
  80.         } else {
  81.             btn = this.template.append(ct, targs, true);
  82.         }
  83.         var btnEl = btn.child("a:first");
  84.         this.btnEl = btnEl;
  85.         btnEl.on('focus', this.onFocus, this);
  86.         btnEl.on('blur', this.onBlur, this);
  87.  
  88.  
  89.         this.initButtonEl(btn, btnEl);
  90.         Ext.ButtonToggleMgr.register(this);
  91.     },
  92.  
  93.     onClick: function (e) {
  94.         if (e.button != 0) return;
  95.  
  96.         if (!this.disabled) {
  97.             this.fireEvent("click", this, e);
  98.  
  99.             if (this.handler) this.handler.call(this.scope || this, this, e);
  100.         }
  101.     }
  102. });
  103.  
  104. Ext.reg('exportbutton', Ext.ux.Exporter.Button);
  105.  
  106.  
  107. //In your main script, create the exporter button as below
  108.  
  109.             var exportButton = new Ext.ux.Exporter.Button({
  110.                 component: _grid,
  111.                 store: someStore, // the store you want to export
  112.                 id: 'exportButton',
  113.                 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
  114.             });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement