Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Howto move ListGrid to a specific rownum

    Hi,
    I want to move the ListGrid to a specific page or rownumber (so that also the scrollbar reflects this position), I checked the source code but it was not directly clear for me on how I can do that.

    I tried by returning the required data page eventhough the listgrid requests another data page. For example the listgrid requests startrow/endrow 0 to 100 and my server returns 500 to 600. This correctly shows the 500-600 rows but the scrollbar does not reflect that there are 500 records before the loaded page (the scrollbar is at the top). And maybe there are other problems with this approach.

    Thanks for any pointers or insight in this!

    gr. Martin

    #2
    There are a couple of things that can help with this.

    First, look at ListGrid.getVisibleRows in order to know which rows are visible at the moment.

    Then, look at ListGrid.body to get the GridRenderer that is actually drawing the rows.

    You can call scrollTo on the GridRenderer to scroll the UI ... that will then automatically generate the relevant DS requests. There is an undocumented scrollToRatio method that is kind of useful ... generally speaking, reading the GridRenderer.js source will help you here.

    Note that you have to do some calculations yourself in terms of row height etc., since scrollTo takes pixels, not records. That's why scrollToRatio is kind of neat ... you can feed it the ratio between the row you want and the total rows. But, of course, it is undocumented.

    Note that I'm thinking in terms of v 7 here ... not sure what has changed in v. 8.

    Comment


      #3
      Here's a bit of code ... not tested in this form, as I'm extracting it from something larger. Assume "this" is the ListGrid, and "rowNumber" is the desired rowNumber

      Code:
      this.body.scrollToRatio(true, rowNumber / this.getTotalRows());
      I forget what the "true" means ... would have to look at GridRenderer.js again. You could implement this with just scrollTo with a little further calculation re: row heights. And I haven't checked v. 8 to see if this works there.

      Comment


        #4
        Just a note that scrollTo is a Canvas method. If you're checking the SmartClient online documentation for classes, it doesn't include the Canvas methods in subclasses (probably to avoid clutter). So when dealing with Canvas subclasses, it is always useful to check Canvas methods as well.

        Comment


          #5
          Hi,
          Thanks for all the pointers!

          I tried this:
          Code:
                rowTop = this.body.getRowTop(startRow);
                this.body.scrollTo(null, rowTop);
          this creates a correct scrollbar, but when scrolling up the rows before the loaded page are empty (see the attached screenshot).
          Using your code I get the same result (and empty rows also).

          Have you ever seen this behavior? Maybe you know how to ensure that previous rows are loaded when scrolling up?

          Or maybe isomorphic knows?

          gr. Martin
          Attached Files
          Last edited by martintaal; 10 Dec 2010, 08:24.

          Comment


            #6
            Enable the ResultSet log category to see what's going on.

            Comment


              #7
              You can also look at Firebug to see what XHR requests are actually being generated.

              In theory, scrollTo should result in various DSRequests going out to get the records for the relevant rows. So, I would check whether:

              (a) are the correct DSRequests being generated?
              (b) are you returning correct results?

              At one point, you were returning non-requested results (as an experiment) ... I'm assuming that you've changed that now!

              Comment


                #8
                Actually the problem I had with empty rows was my mistake...

                To finalize the scroll question. I found this great function on the ListGrid:
                this.scrollRecordIntoView(recordIndex, false);

                This one works perfectly! I had problems with the other proposed scrollTo methods because my grid has something specific that the length of the dataset is not computed, this because the count in the database can take too much time. This resulted in strange interactions with scrollTo, (also because other things were happening asynchronously). Anyway the scrollRecordIntoView works fine.

                Another example of what I like about Smartclient: that there is somehow often a function somewhere which does exactly what I want!

                gr. Martin

                Comment

                Working...
                X