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.
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
togglefunction have theif (!this.table?.element)check, rather than at the beginning of the function, which renders it useless for custom tables.datatables/src/lib/src/shared/builders/ViewBuilder.svelte.ts
Lines 26 to 55 in 755b817
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 thesvelte-dnd-actionexample.