i would like to know how to export grid to excel file with filtered data.
and then choose whether to export the single page or all the pages, always with the filtered data.
This is my component:
<kendo-grid
[data]="gridData"
[pageSize]="state.take"
[skip]="state.skip"
[sort]="state.sort"
[filter]="state.filter"
[sortable]="true"
[pageable]="true"
[filterable]="true"
[selectable]="true"
(dataStateChange)="dataStateChange($event)">
<ng-template kendoGridToolbarTemplate>
<button type="button" kendoGridExcelCommand icon="file-excel">Export To Excel</button>
</ng-template>
<kendo-grid-column field="id" [hidden]=true></kendo-grid-column>
<kendo-grid-column field="name"></kendo-grid-column>
<kendo-grid-column field="surname"></kendo-grid-column>
<kendo-grid-column field="birth_date"></kendo-grid-column>
<kendo-grid-excel fileName="MyFile.xlsx" [fetchData]="allData"></kendo-grid-excel>
</kendo-grid>
TS COMPONENT:
constructor() {
this.allData = this.allData.bind(this);
}
ngOnInit() {
this.getGridData();
}
public allData(): ExcelExportData {
const result: ExcelExportData = {
data: process(this.products, {sort: [{ field: 'name', dir: 'asc' }] }).data
};
return result;
}
getGridData(){
this.MyService.getDataGrid().subscribe(data => {
data = JSON.parse(data);;
this.products= data;
this.gridData = process(data, this.state)
});
}
Thank you,
best regards