Skip to content

Commit

Permalink
feat: add tabulator table
Browse files Browse the repository at this point in the history
  • Loading branch information
invm authored and Michael Ionov committed Aug 8, 2023
1 parent 2197691 commit de3ea5d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 45 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@codemirror/state": "^6.2.1",
"@codemirror/view": "^6.14.1",
"@tauri-apps/api": "^1.4.0",
"@types/tabulator-tables": "^5.4.10",
"@uiw/codemirror-theme-dracula": "^4.21.7",
"fuse.js": "^6.6.2",
"i18next": "^23.1.0",
Expand All @@ -27,6 +28,7 @@
"solid-transition-group": "^0.2.2",
"split.js": "^1.6.5",
"sql-formatter": "^12.2.3",
"tabulator-tables": "^5.5.1",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1",
"tauri-plugin-window-state-api": "github:tauri-apps/tauri-plugin-window-state#v1",
"tinykeys": "^2.1.0",
Expand Down
26 changes: 20 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CloseIcon } from 'components/UI/Icons';
import { ThemeSwitch } from 'components/UI/ThemeSwitch';
import { Console } from 'components/Screens/Console/Console';
import { Home } from 'components/Screens/Home/Home';
import "tabulator-tables/dist/css/tabulator.min.css";

function App() {
const { connectionsService: { removeTab, clearStore, connectionStore, setConnectionStore } } = useAppSelector()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ResultsArea = () => {
return (
<div class="p-3 h-full">
<div class="text-xs font-bold text-primary">Results</div>
<div class="overflow-hidden flex w-full h-full">
<div class="">
<Table data={data()} />
</div>
</div>
Expand Down
50 changes: 12 additions & 38 deletions src/components/UI/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,29 @@
import { createEffect, createSignal, For } from "solid-js";
import { TabulatorFull as Tabulator } from 'tabulator-tables';

export const Table = (props: { data: Record<string, any>[] }) => {
const [columns, setColumns] = createSignal<Record<string, any>[]>([])
const [tabledata, setTableData] = createSignal<Record<string, any>[]>([])

createEffect(() => {
console.log('render')
if (!props.data.length) return;
console.log(props.data.length)
const columns = Object.keys(props.data[0]).map((k) => ({ title: k, field: k }))
console.log(columns)
setColumns(columns)
setTableData(props.data)
console.log(props.data, columns)

new Tabulator('#results-table', {
data: props.data,
columns: columns,
layout: "fitColumns",
resizableColumnFit: true,
});
});

return (
<div class="flex- overflow-hidden">
<div class="overflow-auto h-full">
<table class="table table-xs table-zebra table-pin-rows table-pin-cols">
<thead>
<tr>
<th></th>
<For each={columns()}>
{(column) => (<th>{column.title}</th>)}
</For>
<th></th>
</tr>
</thead>
<tbody>
<For each={tabledata()}>
{(row, i) => (
<tr>
<th>{i() + 1}</th>
<For each={columns()}>
{(column) => (<th>{row[column.field]}</th>)}
</For>
<th>{i() + 1}</th>
</tr>
)}
</For>
</tbody>
<tfoot>
<tr>
<th></th>
<For each={columns()}>
{(column) => (<th>{column.title}</th>)}
</For>
<th></th>
</tr>
</tfoot>
</table>
</div>
<div class="">
<div id="results-table"></div>
</div>
)
}

0 comments on commit de3ea5d

Please sign in to comment.