svelte-headless-table icon indicating copy to clipboard operation
svelte-headless-table copied to clipboard

Feature Request: Cell/Header Attributes

Open huntabyte opened this issue 11 months ago • 3 comments

The createRender function is nice for rendering full-blown components, sometimes all you need is a data-* attribute or class to get the cell where you want it. These attributes could be merged with the ones already provided by the library to spread onto the various elements.

Something along the lines of this:

table.column({
	header: 'Type',
	accessor: 'type',
+ 	cellAttrs: ({ value }) => ({
+		'data-value': value,
+		'data-button': true,
+	}),
+	headerAttrs: () => ({
+		'data-whatever': 'whatever'
+	})
}),

Where the Attrs takes the same params as the respective render properties, but expects a Record<string, unknown> or similar.

If this is something you'd be willing to accept into the library, I'm more than happy to submit a PR - just want your blessing before spending the time @bryanmylee!

huntabyte avatar Mar 16 '24 05:03 huntabyte

@huntabyte he seems to be pretty busy lately, but he answered and merged some of my PRs not long ago.

For the record, I've been using simple components like <Faded/> or <Strong/> for basic styling, and I would benefit from this update!

lolcabanon avatar Mar 22 '24 18:03 lolcabanon

I'm just curious on his insights if this should be a plugin or part of the column definition!

huntabyte avatar Mar 22 '24 22:03 huntabyte

I personally think a plugin would make sense as it would be tree shakable and the design of the plugin system is well adapted for this kind of functionality.

lolcabanon avatar Mar 23 '24 00:03 lolcabanon