Closed JoernT closed 1 year ago
A working solution has been pushed to dev branch. A new demo illustrates usage with different tables and lists.
However there's a limitation: repeats via attributes cannot be nested at this point in time. As the implementation gets significantly more complex when nesting tables i've decided to wait for user feedback and defer this step until a use case comes up. This limitations does NOT apply to usual repeats - those can be nested within a table created via attributes.
A second reason to defer implementation of nested tables is their rather bad performance in browsers - it takes significantly more time for a browser to paint tables than e.g. nested div
structures. This mostly occurs when tables have no fixed dimentions and need several paint runs to get calculated dynamically expecially when they contain other dynamically layed out elements like select
elements.
Instead of merging the functionality now a new fx-repeat-attributes
is used. This share significant portions of the implemenation with fx-repeat
and might be merged at a later stage again. This road was mainly taken to not interfere with the current fx-repeat
element implementation.
Here is the user feedback on "repeats via attributes cannot be nested". I have a sequence of <subject>
s, each containing a sequence of <ref>
s. I want to make a table for each <ref>
, like this:
<fx-repeat ref="instance('article-categories')/subject">
<template>
<div>
<h3>{@title}</h3>
<table>
<tbody data-ref="ref">
<template>
<tr>
<td>{{@label}}</td><td>...</td>
</tr>
</template>
</tbody>
</table>
</div>
</template>
</fx-repeat>
It would be nice if at least an error message is generated in this case. It took me a few hours before I found this issue.
I'm sorry you had trouble. I'll add a clear message on the demo to say that data-ref attributes can only be used as outermost repeated structure.
Btw, usually there's no hard need for tables nowadays as it's always possible to use a structure of 'div' elements and use CSS Grid on them. The only real exception is when you want table headers - these can be difficult to achieve with above method.
Anyway - i apologize for your trouble and try to be more clear on that.
Thank you, Joern. I did end up using display: table
etcetera on nested divs.
I noticed there is a 'header' slot on fx-repeat
. This is nice, but it is always shown. Is there a way to not show the header slot if the fx-repeat/@ref
is empty?
(And is there a way to render an HTML fragment conditionally, something like fx-if
?)
I think there is another use-case for nested iterations with @data-ref
, which is <select><option>...
inside a <fx-repeat>
.
Somehow, the following does not produce options:
<fx-repeat ref="ref">
<template>
<div>{@label}</div>
<div>
<fx-control ref="@doi">
<select class="widget">
<fx-repeat ref="aut">
<template>
<option value="{filename/@id}">
{article-title}
</option>
</template>
</fx-repeat>
</select>
</fx-control>
</div>
</template>
</fx-repeat>
It looks like there is no <fx-repeatitem>
inside the <select>
in the browser inspector:
<fx-repeatitem repeat-index="">
<div>Arens, Hans (1977)</div>
<div>
<select class="widget">
<template>
<option value="{filename/@id}">{article-title}</option>
</template>
</select>
</div>
</fx-repeatitem>
Discussed in https://github.com/Jinntec/Fore/discussions/38
` and may even break styling or require workarounds. So in consequence what we'll need is: ```- {.}
``` ## Possible implementation At initial refresh the fx-form: * querySelectorAll('[data-ref]') * create fx-repeat for each of them like so: ```
::shadowDOM ...
- 1
- 2
- 3
```
`fx-repeat` would become an invisible wrapper around the actual repeated element and:
* move `data-ref` to `fx-repeat/@ref`
* move `` to shadowDOM of repeat
* unroll items
Same principle should work for tables or other similar structures.