Skip to content

Universal CreateView #188

@MrVauxs

Description

@MrVauxs

The table.createView() function sounds like a nice utility function for creating column visibility code. However, it is currently impossible to use on Tables without an element.

It would be great if it was possible to use the function on more than just the bundled datatable by making the toggle function have the if (!this.table?.element) check, rather than at the beginning of the function, which renders it useless for custom tables.

private createColumns(columns: ColumnView[])
{
if (!this.table?.element) {
return
}
clearInterval(this.interval)
this.columns = columns.map(({ name, index, isVisible, isFrozen }) => {
return {
name,
index,
isVisible: isVisible === false ? false : true,
isFrozen: isFrozen === true ? true : false,
element: this.table.element,
toggle: function() {
this.isVisible = !this.isVisible
this.element.querySelectorAll(`tr > *:nth-child(${this.index + 1})`).forEach((element: HTMLElement) => {
element.classList.toggle('hidden')
})
}
}
})
this.preset()
this.mutation = new MutationObserver(() => {
setTimeout(() => {
this.preset()
}, 2)
})
this.mutation.observe(this.table.element, { childList: true, subtree: true })
}

It would also be nice to be able to pass arbitrary objects, and reorder the array with createView, rather than having to write your own solution as shown in the svelte-dnd-action example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions