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

    How to scrollTo a row in a sorted table.

    Help
    3
    4
    309
    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.
    • O
      olaf last edited by

      Hi,

      I have got a table which can be sorted. I want to know how I can find the row index of a row after sorting so I can pass it to the scrollTo method.
      I have made a codepen sample to show the problem.
      Just run the sample and press the scroll to button.
      https://codepen.io/olafxso/pen/eYNydPR

      After that you will see it scrolls to row ‘15 jelly bean’. (it is know the last visible row in the table)

      Then sort the column Calories by clicking on the column header.
      The hit the button again. You will see it scrolls to row ‘51 Ice cream sandwhich’

      Well I would like to know how to scrollto row 15 after sorting a table column.

      Thanks for any idea’s!

      cmanique 1 Reply Last reply Reply Quote 1
      • cmanique
        cmanique @olaf last edited by cmanique

        @olaf

        This is my first answer here, so I hope someone has better ideas 😃

        From what I could understand the scrollTo() is the index on the current state of the table, which apparently you get from computedRows, so you do need to scroll to the index of your row in the computedRows array.

        I tried to do something with filter, but I’m not proficient enough with javascript and failed to return the index of the filtered object.
        Apparently you cannot break forEach, so the following code worked for me:

            scrollTo: function () {
              for (let i = 0; i < this.$refs.table.computedRows.length; i++) {
                if (this.$refs.table.computedRows[i].index === 15) {
                  this.$refs.table.scrollTo(i)
                  break
                }
              }
            }
        

        For the obvious reasons I strongly discourage the usage of this in large data sets and I hope there’s a cleaner solution!

        1 Reply Last reply Reply Quote 2
        • O
          olaf last edited by

          Hi @cmanique ,

          Thanks for pointing me to the computedRows property. I changed it by using the array map prototype.
          This works well after filtering and sorting .

            scrollTo: function () {
                const index = this.$refs.table.computedRows.map(e => e.index).indexOf(15)
                this.$refs.table.scrollTo(index)
              }
          

          I am also pretty new with vue, quasar and javascript. So if any body has got some improvements, I would like to know it.

          metalsadman 1 Reply Last reply Reply Quote 1
          • metalsadman
            metalsadman @olaf last edited by

            @olaf the for loop should perf better, but wouldn’t matter much if the data is not too big.

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