Skip to content

Commit 26a35f4

Browse files
authored
Merge pull request #90 from BEXIS2/table
Table
2 parents ddf94e2 + 8123985 commit 26a35f4

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/lib/components/Table/TableContent.svelte

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
optionsComponent, // Custom component to render in the last column
5151
defaultPageSize = 10, // Default page size - number of rows to display per page
5252
toggle = false, // Whether to display the fitToScreen toggle
53+
search = true, // Whether to display the search input
5354
pageSizes = [5, 10, 15, 20], // Page sizes to display in the pagination component
5455
fitToScreen = true, // Whether to fit the table to the screen,
5556
exportable = false, // Whether to display the export button and enable export functionality
@@ -154,7 +155,7 @@
154155
// Render the cell with the provided component, or use the toStringFn if provided, or just use the value
155156
cell: ({ value, row }) => {
156157
return renderComponent
157-
? createRender(renderComponent, { value, row })
158+
? createRender(renderComponent, { value, row, dispatchFn: actionDispatcher })
158159
: toStringFn
159160
? toStringFn(value)
160161
: value;
@@ -319,8 +320,6 @@
319320
320321
// Format server columns to the client columns
321322
if (response.columns !== undefined) {
322-
console.log(response);
323-
324323
columns = convertServerColumns(response.columns, columns);
325324
326325
const clientCols = response.columns.reduce((acc, col) => {
@@ -369,7 +368,7 @@
369368
{#if $data.length > 0 || (columns && Object.keys(columns).length > 0)}
370369
<div class="table-container">
371370
<!-- Enable the search filter if table is not empty -->
372-
{#if !serverSide}
371+
{#if !serverSide && search}
373372
<form
374373
class="flex gap-2"
375374
on:submit|preventDefault={() => {
@@ -386,6 +385,7 @@
386385
id="{tableId}-search"
387386
/><button
388387
type="reset"
388+
id="{tableId}-searchReset"
389389
class="absolute right-3 items-center"
390390
on:click|preventDefault={() => {
391391
searchValue = '';
@@ -396,6 +396,7 @@
396396
</div>
397397
<button
398398
type="submit"
399+
id="{tableId}-searchSubmit"
399400
class="btn variant-filled-primary"
400401
on:click|preventDefault={() => {
401402
$filterValue = searchValue;
@@ -405,7 +406,7 @@
405406
</form>
406407
{/if}
407408

408-
<div class="flex justify-between items-center py-2 w-full">
409+
<div class="flex justify-between items-center w-full {search && 'py-2'}">
409410
<div>
410411
<!-- Enable the fitToScreen toggle if toggle === true -->
411412
{#if toggle}

src/lib/models/Models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export interface TableConfig<T> {
110110
data: Writable<T[]>;
111111
resizable?: 'none' | 'rows' | 'columns' | 'both'; // none by default
112112
toggle?: boolean; // false by default
113+
search?: boolean; // true by default
113114
fitToScreen?: boolean; // true by default
114115
height?: null | number; // null by default
115116
rowHeight?: number; // auto by default

src/routes/components/table/docs/TableConfigDocs.svelte

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@
4747
</p>
4848
</div>
4949

50+
<div class="items-center">
51+
<div class="flex gap-2">
52+
<div class="italic">search:</div>
53+
<div class="font-bold">boolean</div>
54+
</div>
55+
56+
<p class="text-xl pl-10">
57+
Whether the table should have a search bar. <code
58+
class="!text-xl bg-blue-100 dark:bg-blue-600/30 rounded-md p-0.5 text-blue-500">true</code
59+
> by default.
60+
</p>
61+
</div>
62+
5063
<div class="items-center">
5164
<div class="flex gap-2">
5265
<div class="italic">exportable:</div>

0 commit comments

Comments
 (0)