Skip to content

Commit 9700848

Browse files
committed
Enable searching on server-side
1 parent f0024fb commit 9700848

File tree

1 file changed

+63
-66
lines changed

1 file changed

+63
-66
lines changed

src/lib/components/Table/TableContent.svelte

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -351,77 +351,74 @@
351351
<div class="table-container">
352352
<!-- Enable the search filter if table is not empty -->
353353
{#if $data.length > 0}
354-
{#if !serverSide}
355-
<form
356-
class="flex gap-2"
357-
on:submit|preventDefault={() => {
358-
sendModel.q = searchValue;
354+
<form
355+
class="flex gap-2"
356+
on:submit|preventDefault={() => {
357+
sendModel.q = searchValue;
358+
$filterValue = searchValue;
359+
}}
360+
>
361+
<div class="relative w-full flex items-center">
362+
<input
363+
class="input p-2 border border-primary-500"
364+
type="text"
365+
bind:value={searchValue}
366+
placeholder="Search rows..."
367+
id="{tableId}-search"
368+
/><button
369+
type="reset"
370+
class="absolute right-3 items-center"
371+
on:click|preventDefault={() => {
372+
searchValue = '';
373+
sendModel.q = '';
374+
$filterValue = '';
375+
}}><Fa icon={faXmark} /></button
376+
>
377+
</div>
378+
<button
379+
type="submit"
380+
class="btn variant-filled-primary"
381+
on:click|preventDefault={() => {
359382
$filterValue = searchValue;
360-
}}
383+
sendModel.q = searchValue;
384+
}}>Search</button
361385
>
362-
<div class="relative w-full flex items-center">
363-
<input
364-
class="input p-2 border border-primary-500"
365-
type="text"
366-
bind:value={searchValue}
367-
placeholder="Search rows..."
368-
id="{tableId}-search"
369-
/><button
370-
type="reset"
371-
class="absolute right-3 items-center"
372-
on:click|preventDefault={() => {
373-
searchValue = '';
374-
sendModel.q = '';
375-
$filterValue = '';
376-
}}><Fa icon={faXmark} /></button
377-
>
378-
</div>
386+
</form>
387+
{/if}
388+
<div class="flex justify-between items-center py-2 w-full">
389+
<div>
390+
<!-- Enable the fitToScreen toggle if toggle === true -->
391+
{#if toggle}
392+
<SlideToggle
393+
name="slider-label"
394+
active="bg-primary-500"
395+
size="sm"
396+
checked={fitToScreen}
397+
id="{tableId}-toggle"
398+
on:change={() => (fitToScreen = !fitToScreen)}>Fit to screen</SlideToggle
399+
>
400+
{/if}
401+
</div>
402+
<div class="flex gap-2">
403+
<!-- Enable the resetResize button if resizable !== 'none' -->
404+
{#if resizable !== 'none'}
379405
<button
380-
type="submit"
381-
class="btn variant-filled-primary"
382-
on:click|preventDefault={() => {
383-
$filterValue = searchValue;
384-
sendModel.q = searchValue;
385-
}}>Search</button
406+
type="button"
407+
class="btn btn-sm variant-filled-primary rounded-full order-last"
408+
on:click|preventDefault={() =>
409+
resetResize($headerRows, $pageRows, tableId, columns, resizable)}>Reset sizing</button
386410
>
387-
</form>
388-
{/if}
389-
<div class="flex justify-between items-center py-2 w-full">
390-
<div>
391-
<!-- Enable the fitToScreen toggle if toggle === true -->
392-
{#if toggle}
393-
<SlideToggle
394-
name="slider-label"
395-
active="bg-primary-500"
396-
size="sm"
397-
checked={fitToScreen}
398-
id="{tableId}-toggle"
399-
on:change={() => (fitToScreen = !fitToScreen)}>Fit to screen</SlideToggle
400-
>
401-
{/if}
402-
</div>
403-
<div class="flex gap-2">
404-
<!-- Enable the resetResize button if resizable !== 'none' -->
405-
{#if resizable !== 'none'}
406-
<button
407-
type="button"
408-
class="btn btn-sm variant-filled-primary rounded-full order-last"
409-
on:click|preventDefault={() =>
410-
resetResize($headerRows, $pageRows, tableId, columns, resizable)}
411-
>Reset sizing</button
412-
>
413-
{/if}
414-
{#if exportable}
415-
<button
416-
type="button"
417-
class="btn btn-sm variant-filled-primary rounded-full order-last"
418-
on:click|preventDefault={() => exportAsCsv(tableId, $exportedData)}
419-
>Export as CSV</button
420-
>
421-
{/if}
422-
</div>
411+
{/if}
412+
{#if exportable}
413+
<button
414+
type="button"
415+
class="btn btn-sm variant-filled-primary rounded-full order-last"
416+
on:click|preventDefault={() => exportAsCsv(tableId, $exportedData)}
417+
>Export as CSV</button
418+
>
419+
{/if}
423420
</div>
424-
{/if}
421+
</div>
425422

426423
<div class="overflow-auto" style="height: {height}px">
427424
<table

0 commit comments

Comments
 (0)