Announcement

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

    Freeze visible rows in ListGrid on update

    SmartClient_v120p_2020-01-08_PowerEdition

    I have a ListGrid (autoFetchData: true) with a DataSource (clientOnly: true) that is getting real-time updates (adds, updates, and deletes) via a WebSocket. If I am getting a high volume of added rows, the grid starts auto-scrolling my data (depending on my sort). Is there a way to freeze my current visible rows when updates are flowing in so that the data I am viewing doesn't scroll out of view?

    #2
    Data updates should not, on their own, trigger scrolling, although putting focus in a specific row (via eg startEditing()) would do so.

    Can you clarify the specific scenario where scrolling in occurring, that is:

    1. what is the specific type of update (add, update, multi-column, updating a sorted field?)

    2. what direction does scrolling occur in?

    3. where was the viewport prior to scrolling (eg, top, bottom, middle, slightly offset from either)?

    Finally, scrollToRow() can be used to place scrolling a particular desired position. See also resultSet.updatePartialCache for how updates are performed when we have a partial cache, so it's not possible to place rows at a definite position w.r.rt. server sort order.

    Comment


      #3
      Clarifications:

      1. The specific type of update is an add. When the message comes in, I do a dataSource.addData(message).

      2. The grid scrolls up.

      3. The same behavior occurs regardless of where the viewport is. I mean, if it's at the top already, it stays there obviously, but anywhere else it starts scrolling up.

      Having said all of this, I should add that each message (i.e. record) has an ID field. The grid is sorted by ID descending. Each new message that comes in will have a higher ID than the previous one, so the data automatically gets put at the top of the grid to obey the sort order.

      What I had attempted (with no success) was:
      - Before the addData() call, grid.getVisibleRows() and then retrieve the top record in the viewport using the firstRowNum returned from getVisibleRows()
      - Call addData()
      - Find the new row number of the top record (before the add)
      - Use scrollToRow() to scroll to that row number

      It appears that the grid doesn't know the new row number of the record right away (although the datasource does).

      I will read up on updatePartialCache to see what I'm missing. Thank you.

      Comment


        #4
        addData() is asynchronous even with a client-only DataSource, so if you tried to immediately find out the row number from the ListGrid after calling addData(), that would be expected to fail. Use the callback to addData() to know when the data has been added.

        You may also need to redraw() the ListGrid, depending on how your code is structured, since it may not immediately redraw to show the new row if there were multiple updates.

        Comment

        Working...
        X