File size: 755 Bytes
bdf2455
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<script>
  import {TabulatorFull as Tabulator} from 'tabulator-tables';
  import {onMount} from 'svelte';

  export let data, columns;

  let tableComponent;
  let tab;

  onMount(() => {
    console.log(data, columns);
    // The rows in the data are arrays, but Tabulator expects objects.
    const objs = [];
    for (const row of data) {
      const obj = {};
      for (let i = 0; i < columns.length; i++) {
        obj[columns[i]] = row[i];
      }
      objs.push(obj);
    }
    tab = new Tabulator(tableComponent, {
      data: objs,
      columns: columns.map(c => ({title: c, field: c, widthGrow: 1})),
      height: '311px',
      reactiveData: true,
      layout: "fitColumns",
    });
  });
</script>

<div bind:this={tableComponent}></div>