1

I have a form defined that I use to submit to a PHP script that will create an Excel Spreadsheet using PHPExcel.

Ext.define('Admin.view.main.LedgerParams',{
    extend: 'Ext.window.Window',
    xtype: 'ledgerparams',
    title: 'Generate Account Ledger',           
    defaultFocus: '[name=period]',  
    layout: 'fit',  
    closable: false,
    resizable: false,
    modal : true,
    standardSubmit: true,
    items: [{
        xtype: 'form',      
        layout: 'fit',
        fieldDefaults: {labelWidth: 80,labelAlign: 'right'},
        padding: 10,
        items: [{           
            xtype: 'fieldset',
            padding: 10,
            title: '<b>Account Ledger Parameters</b>',
            defaultType: 'numberfield',
            defaults: {enforceMaxLength: true},
            items:[{                
                name: 'period',
                flex : 1,
                fieldLabel: 'Fiscal Period',
                selectOnFocus: true,
                value: new Date().getFullYear(),
                minValue: 1980
            }]
        }]
    }],
    buttons:[{
        text: 'Generate',
        handler: 'onClick_btnLedgerPrint'
    },{
        text: 'Cancel',     
        handler: function(){this.up('window').destroy();}
    }]
});

The onClick_BtnLedgerPrint method in the main controller calls the form submit:

onClick_btnLedgerPrint: function(btn){                
    btn.up('window').down('form').submit({
    url: 'app/data/Reports.php',
        params: {action:'print',reportname:'generate_ledger'} 
    });
}

however it appears that a JSON response is required by the form from the server instead of initiating the download. Is the standardSubmit broken in ExtJS5? Any help would be appreciated!

Elcid_91
  • 1,571
  • 4
  • 24
  • 50

1 Answers1

1

JavaScript cannot initiate the download, same as Ext JS. Only browser does this.

var formValues = btn.up('window').down('form').getForm().getValues();
var params = { action: 'print', reportname: 'generate_ledger' };
var requestParams = Ext.merge(formValues, params);
var url = 'app/data/Reports.php?' + Ext.Object.toQueryString(requestParams);
document.location = url;

Or you can try to use method with iframe described here

Community
  • 1
  • 1
Alexey Solonets
  • 817
  • 6
  • 15