how to export Virtualization data grid to execl file and select a row when frozenColumns set up?
Hi,
As the data show in data grid will be huge, we use virtualization feature in data grid, the client side only get the data need to refresh when "virtualscroll" begin, the total records around 20000, each time we get 50 record from server in the show datagrid show window, but when we try to export grid data to execl file, nothing happen, we can not save to execl file, please help?
the code like below
<template>
<div class="col-lg-12 control-section">
<div class="content-wrapper">
<ejs-grid ref='refgrid'
width='100%'
height=200
rowHeight=30
:allowFiltering='false'
:allowSorting='true'
:allowResizing='true'
:enableVirtualization='true'
:allowExcelExport="true"
:frozenColumns=3
:pageSettings='pageSettings'
:actionBegin='actionBegin'
...
:columns = datasheetColumns
:dataSource="mapItemPageData" >
</ejs-grid>
</div>
</div>
</template>
<style>
</style>
<script>
//import Vue from "vue";
import { VirtualScroll, Sort, Filter, Resize, Freeze, Selection} from "@syncfusion/ej2-vue-grids";
export default {
name: "MyDataGrid",
props: {
},
watch:{
},
data(){
return {
pageSettings: {
pageSize: 50
},
mapItemPageData:{
result: [],
count: 0
},
datasheetColumns: []
};
},
methods: {
savetofile(){
this.$refs.gmapoverviewgrid.excelExport();
},
actionBegin: function(args) {
if (args.requestType == "virtualscroll") {
const curPage = args.virtualInfo.page;
const recordsToSkip = this.$refs.gmapoverviewgrid.ej2Instances.pageSettings.pageSize * (curPage - 1);
const recordsToTake = this.$refs.gmapoverviewgrid.ej2Instances.pageSettings.pageSize;
var self = this;
WebAPICall(recordsToSkip, recordsToTake, (totalnumber, showitemlist)=>{
self.mapItemPageData = {
result: showitemlist,
count: totalnumber
};
});
}
},
created(){
...Init columns and make a call
var self = this;
WebAPICall(0, 50, (totalnumber, showitemlist)=>{
self.mapItemPageData = {
result: showitemlist,
count: totalnumber
};
});
},
provide: {
grid: [Filter, Selection, Sort, Resize, Freeze, VirtualScroll]
}
};
</script>
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
AG
Ajith Govarthan
Syncfusion Team
July 16, 2020 02:07 PM UTC
Hi CZ,
Thanks for contacting Syncfusion support.
Query: but when we try to export grid data to execl file, nothing happen, we cannot save to execl file, please help?
Based attached code example we suspect that you have not handled the excel export properly and we also found that you have not called the savetofile method anywhere in your sample. So based on your requirement we have prepared sample in we have enabled the virtualization and exported the grid when you click the export button. For your convenience we have attached the sample so please refer the sample for your reference.
Code example:
|
App.vue
methods: {
toolbarClick: function(args) {
//debugger;
if (args.item.id === "Grid_excelexport") {
// 'Grid_excelexport' -> Grid component id + _ + toolbar item name
this.$refs.grid.excelExport();
}
if (args.item.id === "Grid_pdfexport") {
// 'Grid_pdfexport' -> Grid component id + _ + toolbar item name
this.$refs.grid.pdfExport();
}
}
}
methods: {
toolbarClick: function(args) {
//debugger;
if (args.item.id === "Grid_excelexport") {
// 'Grid_excelexport' -> Grid component id + _ + toolbar item name
this.$refs.grid.excelExport();
}
if (args.item.id === "Grid_pdfexport") {
// 'Grid_pdfexport' -> Grid component id + _ + toolbar item name
this.$refs.grid.pdfExport();
}
}
} |
If the above solution doesn’t meet your query then please share the below details.
- If possible please try to reproduce the issue in the attached sample.
- Share the screenshot of the reported issue.
- Share code example of excel export handled in your code.
- Share the Syncfusion package version.
Regards,
Ajith G.
CZ
CZ
July 19, 2020 04:53 PM UTC
2. Exception occur when select a row by click a row in data grid if frozenColumns set up.





Since there are too many columns, so set up to lock first three columns by set up :frozenColumns=3, when we click a row, the row can not selected, we attach detail error information we got from google develop tools. if we don't use froze columns feature, everything works very well, please help!
(1)
(2) In Selection.prototype.selectRow
(3) In getRowObjectFromUID, select row uid are not in the currentModule rows list
below is the code
parameter uid value is "grid-row22"
but current display rows uid is start from "grid-row72", "grid-row22" is not in the list
Thanks,
AG
Ajith Govarthan
Syncfusion Team
July 20, 2020 12:23 PM UTC
Hi CZ,
Thanks for the update.
Query: Exception occur when select a row by click a row in data grid if frozenColumns set up.
We have checked your attached code examples and found that you have tried to use custom data binding in your sample. To achieved your requirement we suggest you to use the actionBegin event to fetch data for the grid component. In EJ2 Grid component we have event called dataStateChange to achieve your requirement.
By default in EJ2 Grid when using Custom binding for Grid data binding then it exports current page records only. If you want to export all page records or some specific records, define the dataSource in exportProperties.
For your convenience we have attached the code example and sample so please refer them for your reference.
|
App.vue
toolbarClick: function(args) {
if (args.item.text === "Excel Export") {
args.cancel = true; // prevent default exporting
let state1 = {
skip: 0,
take: this.$refs.grid.$el.ej2_instances[0].pageSettings
.totalRecordsCount
};
this.orderService.execute(state1).then(gridData => {
debugger; // get all records from service
let excelExportProperties = {
dataSource: gridData.result, // assign result to data source property
fileName: "new.xlsx"
};
this.$refs.grid.excelExport(excelExportProperties); // Export all page records
});
}
} |
|
App.vue
<ejs-grid ref="grid" :dataSource='data' height="400" width="800" :frozenColumns="2" :enableVirtualization="true"
:actionFailure="actionFailure" :toolbarClick="toolbarClick" :dataStateChange='dataStateChange' >
<e-columns>
<e-column field= "OrderID" headerText="Order ID" width="130" textAlign='Right' ></e-column>
<e-column field= "CustomerID" headerText="CustomerID" width="130" textAlign='Right' ></e-column>
<e-column field= "Freight" headerText="Freight" width="130" textAlign='Right' ></e-column>
<e-column field= "ShipCountry" headerText="Country" width="130" textAlign='Right' ></e-column>
<e-column field= "ShipCity" headerText="City" width="130" textAlign='Right' ></e-column>
<e-column field= "ShipAddress" headerText="Address" width="130" textAlign='Right' ></e-column>
</e-columns>
</ejs-grid>
dataStateChange: function (state) {
if (state.action && (state.action.requestType === "filterchoicerequest" || state.action.requestType ==="filtersearchbegin")) {
this.orderService.execute(state).then((e) => {
state.dataSource(e.result);
});
} else {
this.orderService.execute(state).then(( gridData ) => this.data = gridData );
}
|
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/custom_Binding_-_vue-1855390676.zip
Documentation link: https://ej2.syncfusion.com/vue/documentation/api/grid/#datastatechange
Please get back to us if you need further assistance.
Regards,
Ajith G.
Marked as answer
SIGN IN To post a reply.