Skip to content

UTable: row dividers and sticky headers are achievable when virtualized #5464

@JustusBaumhove

Description

@JustusBaumhove

Package

v4.x

Description

Row dividers

As said in the docs borders are not working well with virtualization, but using a css after element works fine. I've implemented row dividers in my library similar to:

  • <tr>: 'relative after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-(--ui-border)'
  • <tbody>: 'last:[&>tr]:after:hidden'

Sticky headers

The issue here is that the scrollable element and the table element have different heights, we simply need to append another after element which is the cheapest to compute for the browser to extend the height. Issue and solution properly explained here:

I grab the height of the tbody element via useElementSize and calculate the difference like:

const tableBodyRef = useTemplateRef('tableBodyRef')
const { height: tableBodyHeight } = useElementSize(tableBodyRef)
const tableStyle = computed(() => {
  const tableAfterHeight = virtualizer.value.getTotalSize() - tableBodyHeight.value
  return { '--after-height': `${tableAfterHeight}px` }
})

// Theme:
virtualize: {
  false: {
    base: 'overflow-clip',
    ...
  },
  true: {
    base: 'after:inline-block after:h-(--after-height)',
    ...
  },
},

In the template I was able to get rid of the reusable table template and extra div by setting that calculated style on the table element itself.

I am aware of the PR for the ScrollArea component and was wondering if it solves these two issues already or if I should try myself on a PR if these workarounds are wanted?

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttriageAwaiting initial review and prioritizationv4#4488

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions