PDA

View Full Version : How to export grid results to email?



varmaj80
28 Jan 2015, 3:04 PM
Hello all,

Can anyone give me an idea on how we can export the grid results to an email?. I am able to do an export to excel sheet but not able to get an idea on how to do the export to an email. I have an right click option when a user clicks on the results grid and export to email is one of those options. I need to export the entire table to an email.

Thanks,

lumberjack
30 Jan 2015, 7:10 AM
That's a bit outside the scope of Sencha Support, and I don't have any experience with that setup myself. I'll defer to the community's collective experience on this one. Best of luck!


Regards,
Brian

yeghikyan
30 Jan 2015, 9:34 AM
Something like this?

Ext.define('ExportableGrid', { extend: 'Ext.grid.Panel',

exportToEmail: function() {
var bodyText = this.getBodyText();
var email = '[email protected]';
//window.open
window.open(this.getEmailUrl(
'[email protected]',
'Export für Muster Musterman',
bodyText
));
},

getEmailUrl: function(email, subject, body) {
var url = 'mailto:' + email
+ "?subject=" + escape(subject)
+ "&body=" + escape(body);
return url;
},

getVisibleColumns: function() {
var columns = [];
Ext.Array.each(this.columns, function(column) {
if(!column.isHidden()) {
columns.push({
text: column.text,
dataIndex: column.dataIndex,
renderer: column.renderer
});
}
});
return columns;
},

getBodyText: function() {
var bodyText = "Your Export\n\n"
+ this.tsvTableRenderer(this.getStore(), this.getVisibleColumns())
+ "\n\nLG\n"
+ "Lisa Simpson\n";


return bodyText;
},

tsvTableRenderer: function(store, columns) {
var tsvTable = this.getTsvTableHeader(columns)
+ "\n"
+ this.getTsvTableBody(store, columns)
return tsvTable;
},

getTsvTableHeader: function(columns) {
var tableHeader = '';
Ext.Array.each(columns, function(columnObj) {
tableHeader += columnObj.text + "\t";
}, this);
return tableHeader;
},

getTsvTableBody: function(store, columns) {
var tableBody = '';
this.getStore().each(function(record) {
Ext.Array.each(columns, function(columnObj) {
if(Ext.isFunction(columnObj.renderer)) {
tableBody += columnObj.renderer(
record.get(columnObj.dataIndex),
{},
record
);
} else {
tableBody += record.get(columnObj.dataIndex);
}
tableBody += "\t";
}, this);
tableBody += "\n";
}, this);
return tableBody;
}
});


Ext.application({
name: 'Fiddle',


launch: function() {
var store = Ext.create('Ext.data.Store', {
fields:['name', 'email', 'phone'],
data:{'items':[
{ 'name': 'Lisa', "email":"[email protected]", "phone":"555-111-1224" },
{ 'name': 'Bart', "email":"[email protected]", "phone":"555-222-1234" },
{ 'name': 'Homer', "email":"[email protected]", "phone":"555-222-1244" },
{ 'name': 'Marge', "email":"[email protected]", "phone":"555-222-1254" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});

var grid = Ext.create('ExportableGrid', {
title: 'Simpsons',
store: store,
dockedItems: [{
xtype: 'toolbar',
items: [{
text: "Export To Email",
handler: function() {
grid.exportToEmail()
}
}]
}],
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{
text: 'Phone',
dataIndex: 'phone',
renderer: function(value) {
return "Tel: " + value;
}
}
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
}
});

This code requires splitting to classes... just dirty concept.