No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Q-tree: Is it possible to add a scrollbar?

    Framework
    1
    2
    316
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • CWoodman
      CWoodman last edited by CWoodman

      I have a dynamically built tree with multiple levels. User can expand all or collapse all using buttons. If expanding the tree makes it longer than the page, I’d like to show a scrollbar.

      And if that’s possible, I’d also like a way to ensure a selected node is visible by auto-scrolling to show it.

      I tried this but it doesn’t work…

      <q-scroll-area>
        <q-tree
          .....
        />
      </q-scroll-area>
      

      I know I can have the whole page scroll, but I want to keep the top toolbar visible while the tree scrolls. I also have another panel beside it with related information which should not scroll with the tree.

      1 Reply Last reply Reply Quote 0
      • CWoodman
        CWoodman last edited by

        Found a way to do it, but probably a better way. Anyway here’s what works for me…
        In the template:

        <div id="treeScroll" class="scroll overflow-hidden">
           <q-scroll-area :style="treeHeightStyle">
               <div class="q-px-sm">
                  <q-tree
                       ....
                  </q-tree>
               </div>
            </q-scroll-area>
        </div>
        

        And in the script:

        mounted () {
          window.addEventListener('resize', this.setTreeHeight)
          this.setTreeHeight()
        },
        destroyed () {
          window.removeEventListener('resize')
        },
        methods: {
          setTreeHeight () {
            const treeTop = document.getElementById('treeScroll').offsetTop
            const treeHeight = window.innerHeight - treeTop
            this.treeHeightStyle = 'height: ' + treeHeight + 'px'
          }
        },
        data () {
          return {
            treeHeightStyle: '',
            ...
        }
        

        If anyone has a better approach, let’s hear it. Otherwise, maybe someone else will benefit from this post.
        Still haven’t figured out how to ensure the selected tree item is visible.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post