-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types are nuts but the table works with the proper CSS.
- Loading branch information
Showing
8 changed files
with
148 additions
and
163 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,69 @@ | ||
<script lang='ts'> | ||
import { Grid } from 'wx-svelte-grid'; | ||
import { Willow } from 'wx-svelte-grid'; | ||
import {TabulatorFull as Tabulator} from 'tabulator-tables'; | ||
import {onMount} from 'svelte'; | ||
import type { TabulatorFull } from 'tabulator-tables'; | ||
interface Props { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
data: any[]; | ||
data?: any[]; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
columns?: any[]; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
options?: any; | ||
} | ||
let { data, columns = [] }: Props = $props(); | ||
let { | ||
data = [], | ||
columns = [], | ||
options = {} | ||
}: Props = $props(); | ||
/**@type {import('tabulator-tables').Tabulator}*/ | ||
let tableObject : TabulatorFull; | ||
let tableRef : HTMLDivElement; | ||
onMount(() => { | ||
if (data) { | ||
tableObject = new Tabulator(tableRef, { | ||
data , | ||
columns , | ||
layout : 'fitColumns' , //fit columns to width of table | ||
addRowPos : 'top' , //when adding a new row add it to the top of the table | ||
paginationSize : 50 , //allow 7 rows per page of data | ||
pagination : true , //paginate the data | ||
paginationCounter : 'rows' , //display count of paginated rows in footer | ||
responsiveLayout : 'hide' , //hide columns that don't fit on the table | ||
movableColumns : true , //allow column order to be changed | ||
resizableColumnFit : true, | ||
}); | ||
} else { | ||
tableObject = new Tabulator(tableRef, { | ||
layout : 'fitColumns' , //fit columns to width of table | ||
responsiveLayout : 'hide' , //hide columns that don't fit on the table | ||
addRowPos : 'top' , //when adding a new row add it to the top of the table | ||
paginationSize : 50 , //allow 7 rows per page of data | ||
pagination : true , //paginate the data | ||
paginationCounter : 'rows' , //display count of paginated rows in footer | ||
movableColumns : true , //allow column order to be changed | ||
}); | ||
} | ||
return () => tableObject.destroy(); | ||
}); | ||
</script> | ||
|
||
<Willow> | ||
<Grid {data} {columns} /> | ||
</Willow> | ||
<div style="text-align: right; padding-bottom: 4px;"> | ||
<button onclick={ () => { tableObject.download('csv', options.filename || 'tabroom-data.csv') } } > | ||
CSV | ||
</button> | ||
</div> | ||
|
||
<div bind:this={tableRef}></div> | ||
|
||
<svelte:head> | ||
<link href="/css/tabulator.min.css" rel="stylesheet"> | ||
</svelte:head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.