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

[Feature request] Dynamic table content - Svelte #232

Open
piotrowski opened this issue May 23, 2022 · 3 comments
Open

[Feature request] Dynamic table content - Svelte #232

piotrowski opened this issue May 23, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@piotrowski
Copy link
Contributor

Hello. Following what we talked at gitter 😄

Use case:

I want to be able to press X mark and remove every line I want. Right now it is not possible, as there is no callback from renderComponent.

MY solution

  1. Add handleUpdate function to headers. This function is basically overwriting tabelArgs with new value:
headers: [
		...		
		{
			label: 'Remove',
			key: 'interactive',
			width: '10%',
			handleUpdate: handleUpdate,
			renderComponent: () => RemoveRow
		}
],
  1. Add event to svelte:component (I have extracted code from yarn package)
<svelte:component
	this={headers[cIndex].renderComponent()}
	on:update={headers[cIndex].handleUpdate}
	{...{ cellValue: row[key] }}
/>
  1. Inside the renderComponent I have code that dispatches event:
dispatch('update', {
        id: cellValue.id
});

So as you see it is quite easy to do, however it involves adding new field to headers API.

@roblevintennis
Copy link
Contributor

roblevintennis commented May 24, 2022

I like the overall idea and direction 👍

I have some question just for clarification and so I have full context…

In your example 2. I'm interpreting that as some code you've extracted from the node modules package and I'm wondering why it's headers (perhaps it's an older version?); I think those are mapped to columns:
https://github.com/AgnosticUI/agnosticui/blob/master/agnostic-svelte/src/lib/components/Table/Table.svelte#L370
This is probably a non-issue I just want to make sure I'm understanding your example 100%.

I'm wondering what is handleUpdate meant for exactly? The use case here is row removal, but I think if we have a handleUpdate the consumer might do other things too no? CRUD? https://socket.dev/npm/package/svelte-generic-crud-table appears to support firing CRUD events individually on:remove, on:update, on:create etc. (although their implementation is built to support more sophisticated CRUD operations as part of its feature set; ours does not...at least not yet and it would be ideal if we can let consumer handle most of the logic control inverted if possible).

Maybe I'm hung up on the "update" part being so closely a part of CRUD. If we feel a single event is simplest I suppose we could also call it handleChange just to differentiate from CRUD.

All said, I think you're basically just dispatching an event so the consumer will "known" that cellValue.id has been updated somehow. What's triggering the updates internal to the table in the first place?

Another question. When the consumer receives on:update callback, are they going to get the table to re-render by passing in updated rows props or? That's the goal correct? Consumer will remove the row in its local code then pass in the list of rows after such removal?

@Croug you've done the most work in the Table / Pagination of late. Do you have any input, questions or concerns here?

@piotrowski
Copy link
Contributor Author

Yeah, you could call it handleChange function. It is fired after being dispatched from Table. It works just like you said, I am rerendering full table each time, might be not ideal, but good enough for my case.

@roblevintennis
Copy link
Contributor

Ok thanks for clarifying @apiotrowski312 -- let's cut a PR when you can 👍🏽

@roblevintennis roblevintennis reopened this Jun 6, 2022
@roblevintennis roblevintennis added the enhancement New feature or request label Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants