muonw / muonw-powertable

▦ PowerTable is a Svelte component that turns JSON data into an interactive HTML table. Inspired by DataTables. Powered by Svelte.
https://muonw.github.io/muonw-powertable/
Other
220 stars 13 forks source link

Passing additional props to component #26

Closed paulocr closed 1 year ago

paulocr commented 1 year ago

Hello,

First of all thanks for the great work. I want to ask if it's possible to pass additional props to a component.

My use case is I want to reuse the component in other areas but I want to change the layout depending on where it's used.

I was thinking of something like this:

    key: 'subscriptions',
    title: 'Subscripciones',
    parseAs: 'component',
    dataComponent: TableComponent({..., additionalProp: 'table'})

Thanks!

paulocr commented 1 year ago

For my use case I thought about it a little better and I guess I can leverage rowId and rowIndex to detect when the component is being called from PowerTable but I still would be interested to know if you have any thoughts on adding additional props. Thanks!

muonw-public commented 1 year ago

I don't think it's feasible to pass custom props, but as you pointed out you can use rowId and rowIndex (as well as value) props and let your component decide what to render.

The new release (v2.3.4) also makes instructKey available to your component. So, if you plan to reuse your component across different columns, you can now detect the column using instructKey.

paulocr commented 1 year ago

Thank you!