showing results for - "angular table lazy loading"
Abi
09 Jan 2017
1  onFileSelected(files: FileList) {
2
3    console.log(files)
4    console.log(files[0])
5
6    this.csvIsParsing = true;
7
8    let file = files[0];
9    // xls is the same MIME type like csv
10    let csvType = "application/vnd.ms-excel";
11    let xlsxType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
12
13    if (file.type !== csvType && file.type !== xlsxType) {
14      this.wrongFileTypeError = true;
15      this.csvIsParsing = false;
16      return;
17    } else if (files.length > 1) {
18      this.tooManyFilesError = true;
19      this.csvIsParsing = false;
20      return;
21    }
22
23    this.fileName = file.name;
24    this.checkFileSize(file.size);
25
26    this.wrongFileTypeError = false;
27    this.tooManyFilesError = false;
28
29    if (files.length > 0 && file.type === csvType) { //temporarily
30
31      this.csvParser.parse(file, {
32        header: this.hasCsvHeader,
33        skipEmptyLines: true,
34        dynamicTyping: true,
35        // dynamicTyping: true, lässt 0 verschwinden vor 010000
36        encoding: "ISO-8859-1",
37        complete: (result) => {
38          console.log('Parsed: ', result.data);
39          this.csvData = result.data;
40          this.dataSource = new MatTableDataSource(result.data);
41          this.dataSource.sort = this.sort;
42          setTimeout(() => this.dataSource.paginator = this.paginator);
43          for (let col in this.csvData[0]) {
44            this.displayedColumns.push(col);
45          }
46          console.log(this.dataSource);
47          this.csvIsParsing = false;
48        }
49      });
50    }
51  }
52