Enable lazy loading for trees #3945
Replies: 2 comments 7 replies
-
Hi @moi90, That would be a nice addition to the One workaround is to use a JavaScript event handler: ui.tree([{'id': 'A', 'lazy': True}], label_key='id') \
.on('lazy-load', js_handler='''({ node, key, done, fail }) => {
done([
{ id: `${node.id}.1`, lazy: true },
{ id: `${node.id}.2`, lazy: true },
]);
}''') Of course, this only makes sense if all information about nested nodes can be expressed as a JavaScript function. @app.get('/children')
def get_children(node_id: str):
return [
{'id': f'{node_id}.1', 'lazy': True},
{'id': f'{node_id}.2', 'lazy': True},
]
ui.tree([{'id': 'A', 'lazy': True}], label_key='id') \
.on('lazy-load', js_handler='''({ node, key, done, fail }) => {
fetch(`/children?node_id=${node.id}`)
.then(response => response.json())
.then(data => done(data))
.catch(fail);
}''') Wrapping this approach into a nice API would be great, but not necessarily straightforward. Especially creating and pruning the additional endpoint needs to be done correctly to avoid memory leaks. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your suggestions! Would it be hard to enable event handlers to send a return value back to the client? Maybe it could be useful in other places, too. (I have not yet used the library, so I don't have a feeling for that. But I'm about to use it :)) |
Beta Was this translation helpful? Give feedback.
-
Quasar Tree provides a way to lazily load children when a node is expanded. It would be great to expose this functionality in the nicegui API.
Beta Was this translation helpful? Give feedback.
All reactions