bryanmylee / svelte-headless-table

Unopinionated and extensible data tables for Svelte
https://svelte-headless-table.bryanmylee.com/
482 stars 31 forks source link

Clickable row? #104

Open risalfajar opened 1 year ago

risalfajar commented 1 year ago

Is any plugin to add click event to each row with its corresponding data as argument?

bryanmylee commented 1 year ago

Could you add an event handler on your <tr/> element?

If not, you would have to write a custom plugin to do so.

risalfajar commented 1 year ago

Yes currently it's possible to implement this

{#each $rows as row (row.id)}
    <Subscribe rowAttrs={row.attrs()} let:rowAttrs>
        <tr {...rowAttrs} class:clickable on:click={() => dispatch('click', row.original)}>
            {#each row.cells as cell (cell.id)}
                <Subscribe attrs={cell.attrs()} let:attrs>
                    <td {...attrs}>
                        <Render of={cell.render()}/>
                    </td>
                </Subscribe>
            {/each}
        </tr>
    </Subscribe>
{/each}

But maybe having a plugin to do this is a nice to have.

bryanmylee commented 1 year ago

Yeah it would be nice to have a plugin to attach listeners to table elements. I'll look into it!

fstodulski commented 9 months ago
Screenshot 2024-01-09 at 18 25 51

Hey! is it possible to add simple way to pass an ID for Navigating Purposes? Also, row.original seems to have an issue with types.

lfsc09 commented 8 months ago

Hey @fstodulski, take a look at https://github.com/bryanmylee/svelte-headless-table/issues/31#issuecomment-1167195138. I've resolved my type issues with row.original with it.