📜  角表延迟加载 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:04:09.560000             🧑  作者: Mango

代码示例1
onFileSelected(files: FileList) {

    console.log(files)
    console.log(files[0])

    this.csvIsParsing = true;

    let file = files[0];
    // xls is the same MIME type like csv
    let csvType = "application/vnd.ms-excel";
    let xlsxType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

    if (file.type !== csvType && file.type !== xlsxType) {
      this.wrongFileTypeError = true;
      this.csvIsParsing = false;
      return;
    } else if (files.length > 1) {
      this.tooManyFilesError = true;
      this.csvIsParsing = false;
      return;
    }

    this.fileName = file.name;
    this.checkFileSize(file.size);

    this.wrongFileTypeError = false;
    this.tooManyFilesError = false;

    if (files.length > 0 && file.type === csvType) { //temporarily

      this.csvParser.parse(file, {
        header: this.hasCsvHeader,
        skipEmptyLines: true,
        dynamicTyping: true,
        // dynamicTyping: true, lässt 0 verschwinden vor 010000
        encoding: "ISO-8859-1",
        complete: (result) => {
          console.log('Parsed: ', result.data);
          this.csvData = result.data;
          this.dataSource = new MatTableDataSource(result.data);
          this.dataSource.sort = this.sort;
          setTimeout(() => this.dataSource.paginator = this.paginator);
          for (let col in this.csvData[0]) {
            this.displayedColumns.push(col);
          }
          console.log(this.dataSource);
          this.csvIsParsing = false;
        }
      });
    }
  }