Hello,
We are using SmartClient_70rc2_Pro.
We get data from server through RPCManger.sendRequest call, and use setData to populate the Grid. We use clientOnly data source for the filter to work. Since all the data are at the client side, and we enable grid sort and filter, it is easy to do the export directly at the client side, as it will be quite some extra work to keep track of the sort and filter at the server side. Our data are not directly retrieved from a database table.
I’m thinking to directly export the data at the client side using ActiveXObject. But there is a warning dialog (saying “An Active X control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?”) pops up every time user do the export. The warning message might not be acceptable to our client. Plus, the export might not work because of user browser settings.
Do you have any suggestions on how to export the data to Excel in this case?
Thanks in advance.
The following is a sample code showing our export is done:
<HTML><HEAD>
<SCRIPT>var isomorphicDir="../isomorphic/";</SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Core.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Containers.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Grids.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Forms.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
<SCRIPT SRC=../isomorphic/skins/TreeFrog/load_skin.js></SCRIPT>
</HEAD><BODY>
<SCRIPT>
try{
ctAddButton.show();
} catch (err) {
isc.IButton.create({
ID:"ctAddButton",
title: "Export",
width:100,
top:50,
left:200,
click: function() {
startExcel();
}
})
}
isc.DataSource.create({
ID:"fsEnumDataSource",
fields:[
{name:"c0", title:"c0", width:100, type:"text", showHover:true},
{name:"c1", title:"c1", width:100, type:"text", showHover:true}
],
clientOnly:true
});
isc.ListGrid.create({
ID: "ctDisplayDataGrid",
showFilterEditor: true,
filterOnKeypress: true,
canPickFields:false,
left:100,
top:100,
autoFitFieldWidths:true,
autoFetchData:true,
canReorderRecords: true,
autoDraw:true,
dataSource:"fsEnumDataSource"
});
var MAX_COL = 2;
var MAX_ROW = 4;
var data = Array.create();
for ( r=0; r<MAX_ROW; r++){
row = Array.create();
for ( i=0; i<MAX_COL; i++){
row["c"+i]="row"+r+"col"+i;
}
data.add(row);
}
ctDisplayDataGrid.setData(data);
fsEnumDataSource.testData=data;
function startExcel() {
var xls = new ActiveXObject ( "Excel.Application" );
xls.visible = true;
var excelSheet = xls.Workbooks.Add;
excelSheet.Worksheets.Add;
excelSheet.Worksheets(1).Activate;
for(i=0; i<ctDisplayDataGrid.fields.length; i++){
excelSheet.Worksheets(1).Cells(1, i+1).value=ctDisplayDataGrid.fields[i].title;
}
var row = null;
var j = 0;
for(i=0; i<ctDisplayDataGrid.data.length; i++){
row = ctDisplayDataGrid.data[i];
for(j=0; j<ctDisplayDataGrid.fields.length; j++){
excelSheet.Worksheets(1).Cells(i+2, j+1).value=row["c"+j];
}
}
excelSheet.Worksheets(1).Name="Custom Report";
}
</SCRIPT>
</BODY></HTML>
We are using SmartClient_70rc2_Pro.
We get data from server through RPCManger.sendRequest call, and use setData to populate the Grid. We use clientOnly data source for the filter to work. Since all the data are at the client side, and we enable grid sort and filter, it is easy to do the export directly at the client side, as it will be quite some extra work to keep track of the sort and filter at the server side. Our data are not directly retrieved from a database table.
I’m thinking to directly export the data at the client side using ActiveXObject. But there is a warning dialog (saying “An Active X control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?”) pops up every time user do the export. The warning message might not be acceptable to our client. Plus, the export might not work because of user browser settings.
Do you have any suggestions on how to export the data to Excel in this case?
Thanks in advance.
The following is a sample code showing our export is done:
<HTML><HEAD>
<SCRIPT>var isomorphicDir="../isomorphic/";</SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Core.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Containers.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Grids.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_Forms.js></SCRIPT>
<SCRIPT SRC=../isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
<SCRIPT SRC=../isomorphic/skins/TreeFrog/load_skin.js></SCRIPT>
</HEAD><BODY>
<SCRIPT>
try{
ctAddButton.show();
} catch (err) {
isc.IButton.create({
ID:"ctAddButton",
title: "Export",
width:100,
top:50,
left:200,
click: function() {
startExcel();
}
})
}
isc.DataSource.create({
ID:"fsEnumDataSource",
fields:[
{name:"c0", title:"c0", width:100, type:"text", showHover:true},
{name:"c1", title:"c1", width:100, type:"text", showHover:true}
],
clientOnly:true
});
isc.ListGrid.create({
ID: "ctDisplayDataGrid",
showFilterEditor: true,
filterOnKeypress: true,
canPickFields:false,
left:100,
top:100,
autoFitFieldWidths:true,
autoFetchData:true,
canReorderRecords: true,
autoDraw:true,
dataSource:"fsEnumDataSource"
});
var MAX_COL = 2;
var MAX_ROW = 4;
var data = Array.create();
for ( r=0; r<MAX_ROW; r++){
row = Array.create();
for ( i=0; i<MAX_COL; i++){
row["c"+i]="row"+r+"col"+i;
}
data.add(row);
}
ctDisplayDataGrid.setData(data);
fsEnumDataSource.testData=data;
function startExcel() {
var xls = new ActiveXObject ( "Excel.Application" );
xls.visible = true;
var excelSheet = xls.Workbooks.Add;
excelSheet.Worksheets.Add;
excelSheet.Worksheets(1).Activate;
for(i=0; i<ctDisplayDataGrid.fields.length; i++){
excelSheet.Worksheets(1).Cells(1, i+1).value=ctDisplayDataGrid.fields[i].title;
}
var row = null;
var j = 0;
for(i=0; i<ctDisplayDataGrid.data.length; i++){
row = ctDisplayDataGrid.data[i];
for(j=0; j<ctDisplayDataGrid.fields.length; j++){
excelSheet.Worksheets(1).Cells(i+2, j+1).value=row["c"+j];
}
}
excelSheet.Worksheets(1).Name="Custom Report";
}
</SCRIPT>
</BODY></HTML>
Comment