Infinite scrolling of a TableView
-
Hi all,
Is it possible to create a QML TableView with infinite scrolling, so I can load more data into it dynamically when the scroll reaches the end?
For example, this is possible on a ListView using the code below, but I couldn't find a way to do it on a TableView:
onAtYEndChanged: {
if(atYEnd) sigEndOfListReached()
}
Thank you,
Bruno. -
Yes, it can be done in the same way as in all Qt's MVC classes: subclass QAbstractItemModel and reimplement canFetchMore() and fetchMore() methods. It might look scary at first sight, but is really super-easy.
-
Hi Sierdzio, thank you for the quick response, but that's not the kind of solution I'm looking for.
I don't want to subclass QAbstractItemModel for each TableView I have (many!). Meanwhile, I just created a navigation bar where the user can move backward/forward manually. :-(
Thanks again/Bruno. -
Nobody forces you to subclass QAbstractItemModel multiple times. Just like ListModel can work on different data, so can the QAbstractItemModel, when applied carefully. As for navigation: QtQuick.Controls have a built-in ScrollBar item, if you are interested.
If you still want to do it purely in QML, though, here is an idea:
TableView { onCurrentRowChanged: { if (currentRow > (0.9 * rowCount)) { // insert more rows } } }
-
@ParCHAT1497 said in Infinite scrolling of a TableView:
@sierdzio Hi i want to implement something similar... i am not able to fetch the position of scrollbar.. how can I do it ?
See the original post by @tezine it includes exact code you need.
-