Search code examples
extjsextjs4

How to open new browser window onclick of button in grid panel in extjs 4


I am new to Extjs. I am trying to open a log file in new browser window when i click on the button in grid panel in Extjs 4.

I am able to download that file. But I don't want to download it, I want that it should get opened in new browser window when I click on that button.

I am doing this:

{
    xtype: 'gridpanel',
    id: 'logResultGrid',
    margin: '40 0 10 20',

    width: 439,

    title: 'Logs Result:',
    store: 'LogsStore',

    viewConfig: {
        id: 'logsGrid'
    },

    columns: [{
        xtype: 'gridcolumn',
        renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
            var directoryName = Ext.getCmp('logsJobName').getValue();
            return '<a href="http://localhost:40889/Snowy/fileDownload/download.htmreportName=' + value + '&directoryName=' + directoryName + '">' + value + '</a>';
        },
        width: 297,
        dataIndex: 'fileName',
        text: 'Log Name'
    }, {
        xtype: 'actioncolumn',
        width: 116,
        items: [{
            handler: function(view, rowIndex, colIndex, item, e) {
                var my_record = view.getSelectionModel().getLastSelected();

                var directoryName = Ext.getCmp('logsJobName').getValue();
                var rec = Ext.StoreMgr.lookup("LogsStore").getAt(rowIndex);
                var my_url = 'http://localhost:40889/Snowy/fileDownload/download.htm?reportName=' + rec.data.fileName + '&directoryName=' + directoryName;

                // new Ext.Window({
                //  width: 500,
                //  height: 500,
                //  html: '<iframe width="300" height="300" src="' + my_url + '"</iframe>'
                // }).show();

                window.open(my_url, "_blank");
                //});
            },
            icon: 'resources/images/Open-Folder-Info-icon.png'
        }]
    }],

    selModel: Ext.create('Ext.selection.CheckboxModel', {

    })

}

By doing the above , I can download that file.I am using renderer to download that file.To open that file in new browser window I am using handler. I am using java as my backend.

Please correct me if I am doing something wrong in this. I am struggling since past two days.

Thanks in advance.


Solution

  • You should just be able to use plain Javascript to achieve this:

    {
        xtype: 'button',
        text: 'Open Log',
        handler: function() {
            window.open('myLog.txt');
        }
    }