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

How to calculate/recalculate row height with expandable content? #30

Open
ghost opened this issue Dec 13, 2023 · 0 comments
Open

How to calculate/recalculate row height with expandable content? #30

ghost opened this issue Dec 13, 2023 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@ghost
Copy link

ghost commented Dec 13, 2023

I need to build expandable table, on button click content as sub-row must appear.
I have big problem figuring out how to calculate dynamic height on render (page crashes) and to recalculate height on row expand. Please give me some hint.

<script>
	import VirtualList from 'svelte-tiny-virtual-list';
	let virtualList;
	let expanded = [1, 5];
        let rows = [1,2,3,4,5,6,7,8,9,10]
	let columns = [
		{
			id: 'testCol'
		}
	];

	let heights = [];
	$: console.log(heights);
</script>

<div>
	<div class="w-[500px]">
		<VirtualList
			width="100%"
			height={600}
			itemCount={rows.length}
			itemSize={(i) => heights[i]}
			bind:this={virtualList}
		>
			<div class="" slot="item" let:index let:style {style} bind:clientHeight={heights[index]}>
				{#each columns as column}
					{@const row = rows[index]}
					<div class=" px-sm table-cell">
						<button
							on:click={() => {
								let newArr = [];

								if (!expanded.includes(index)) {
									expanded = [...expanded, index];
									return;
								}

								expanded.map((i) => {
									if (i != index) {
										newArr.push(i);
									}
								});
								expanded = newArr;

								virtualList.recomputeSizes(0);
							}}>Expand trigger button</button
						>
					</div>
				{/each}
				{#if expanded.includes(index)}
					<div class="bg-red-200 w-full">
						<div class="text-right">Expended row content</div>
					</div>
				{/if}
			</div>
		</VirtualList>
	</div>
</div>
@jonasgeiler jonasgeiler self-assigned this Feb 12, 2024
@jonasgeiler jonasgeiler added the question Further information is requested label Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant