Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal]: Add dynamic slots for KTable columns #743

Open
AlexVelezLl opened this issue Aug 21, 2024 · 1 comment
Open

[Proposal]: Add dynamic slots for KTable columns #743

AlexVelezLl opened this issue Aug 21, 2024 · 1 comment
Labels
Component: KTable TODO: needs decisions Further discussion and planning necessary type: proposal New feature or request

Comments

@AlexVelezLl
Copy link
Member

Product

KDS.

Desired behavior

I would like to be able to customize the contents of certain columns in a table using dynamic slots. For example:

We can pass an id to our headers array:

headers: [
  { label: 'Name', dataType: 'string' },
  { label: 'Age', dataType: 'numeric' },
  { label: 'City', dataType: 'string', id: "city" },
],

And for the columns that have that id we can add a slot with that name to have specific content for that column:

<KTable
  :headers="headers"
  :rows="rows"
  caption=""
  :sortable="false"
>
  <template #cell="{ content }">
    <span> {{ content }} </span>
  </template>
  <template #city="{ content }">
    <span>{{ content }} (City)</span>
  </template>
</KTable>

So if there is a column that has a dynamic slot, use that slot to render its content, otherwise use the default #cell.

Current behavior

Currently if I wanted custom content for the city column, I have to use the colIndex of that column:

<KTable
  :headers="headers"
  :rows="rows"
  caption=""
  :sortable="false"
>
  <template #cell="{ content, rowIndex, colIndex }">
    <span v-if="colIndex === 2">{ content } (City)</span>
    <span v-else>{ content }</span>
  </template>
</KTable>

The Value Add

This improves maintainability as if we change the position of the headers, or prepends any column, we wouldnt have to change the template or have to deal with counting which index corresponds to each attribute.

Possible Tradeoffs

We must find an effective way to communicate this in the api docs. Since it can be a bit confusing to have something like a dynamic slot in the slots table in the documentation.

@AlexVelezLl AlexVelezLl changed the title [Proposal]: Add dynamic slots for KTable cells [Proposal]: Add dynamic slots for KTable columns Aug 21, 2024
@MisRob MisRob added the TODO: needs decisions Further discussion and planning necessary label Aug 22, 2024
@MisRob
Copy link
Member

MisRob commented Aug 22, 2024

Nice proposal.

I'd even go as far as to make id required on all header items, rather than just adding it to the ones we want to use their corresponding named slot for. Otherwise I already see devs debugging why a named slot doesn't work, just to find out there's forgotten id :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: KTable TODO: needs decisions Further discussion and planning necessary type: proposal New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants