我有一个使用动态列制作的kendo网格。后端需要两个日期,并在两个日期之间输出数据网格。每个星期都有一列,看起来是这样的:
由于用户可以手动选择日期范围,因此列数是动态的。我已经通过在component.ts文件中执行以下操作来解决该问题:
t1 <- data.frame(FirstName= c('a','b','c','d'), stringsAsFactors = FALSE)
t2 <- data.frame(Name= c('a','b','c'), stringsAsFactors = FALSE)
library(dplyr)
t1 %>%
left_join(mutate(t2, Name2 = Name), c('FirstName' = 'Name2'))
# FirstName Name
#1 a a
#2 b b
#3 c c
#4 d <NA>
和我的component1.html看起来像这样:
import { Component, OnInit, Injectable } from '@angular/core';
import { DataService } from '../data.service';
import { Plants } from '../Plants';
import { DatePipe } from '@angular/common';
@Component({
selector: 'app-component1',
templateUrl: './component1.component.html',
styleUrls: ['./component1.component.css']
})
@Injectable()
export class Component1Component implements OnInit {
constructor(private dataService: DataService) { }
public tableData: [];
public columns: Array<string>;
public currentDate = new Date(Date.now());
public startDate: Date;
public endDate: Date;
public datePipe = new DatePipe('en-US');
ngOnInit() {
this.endDate = this.currentDate;
if (this.currentDate.getMonth() < 9) {
this.startDate = new Date();
this.startDate.setFullYear(this.currentDate.getFullYear() - 1);
this.startDate.setMonth(9);
this.startDate.setDate(1);
} else {
this.startDate = new Date();
this.startDate.setFullYear(this.currentDate.getFullYear());
this.startDate.setMonth(9);
this.startDate.setDate(1);
}
this.getTableData();
}
getTableData() {
const sdate = this.datePipe.transform(this.startDate, 'yyyy-MM-dd');
const edate = this.datePipe.transform(this.endDate, 'yyyy-MM-dd');
this.dataService.getData(Plants.Name, sdate, edate).subscribe(results => {
this.tableData = results['Table'];
this.columns = Object.keys(results['Table'][0]);
for (let i = this.columns.length - 1; i >= 0; i--) {
if (this.columns[i] === 'PlantName' ||
this.columns[i] === 'Department' ||
this.columns[i] === 'GLAccount' ||
this.columns[i] === 'AccountDescription') {
this.columns.splice(i, 1);
}
}
console.log(this.columns);
});
}
}
}
我尝试使用kendo-grid-excel和kendo-excelexport导出。它们都在我的excel文件中呈现静态列,但是均未呈现动态列数据。如何导出数据?