Announcement

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

    Hot to Capture When ListGrid Completely Loaded?

    SmartGWT Power 2.3 - December build

    I'm sure there is a quick answer to this .. so I'll apologize up front for not being able to make it work.

    I created a ListGrid (class) which populates via a SQL Datasource. All works great. One of the columns is a modification date. I have a requirement to track & display the single most recent date for all rows and display it - as in
    "data last modified YYYY-MM-DD".

    I created a CellFormatter for that ListGridField which compares the current date value to a saved value and stores it as a member in the ListGrid (getters/setters available). I can walk it in the debugger and see the compares working and value storing.

    My problem is timing ... I'm trying to grab that date value from the ListGrid when the grid is done loading before it all displays, and I've tried onDraw and dataArrived handlers on the ListGrid, but in debug, those are executed before the CellFormatter executes.

    I have this hierarchy, and I tried onDraw for the layout as well.

    Tabset
    -Tab
    --VLayout
    ---Window (it's a dashboard)
    ----ListGrid

    What event on what UI element will indicate when the ListGrid is loaded making the saved date value available before it all draws?

    Thanks in advance.

    #2
    First of all, if you're going to compute the highest date in the dataset client-side, this means you can't use data paging. So you might want to do this server-side, possibly even by using SQL Templating to add a max() function.

    If you continue down the client-side path, you want to store the highest date value as an instance variable on the ListGrid when DataArrived fires, then use that value when the CellFormatters are called during rendering.

    Comment


      #3
      Using Smart GWT 3.0 nightly builds.

      I'm piggy-backing off this question because my issue is essentially the same as the thread title but if I get no 'hits' I may create a new thread.

      I've noticed this issue in several areas of my web application.

      Here's the brief summary:
      * Using list grids with data paging
      * Need to perform an action when the grid is 'displayed'
      * Since the data is being fetched from the server, there's an initial lag between when the data arrives and the Smart GWT UI 'renders' the grid data
      * The ListGrid methods I'm trying to use on the listgrid require a 'loaded' and 'rendered' list grid.

      Now an exact issue I'm facing:
      * I have a ListGrid that gets shown to the user when the user clicks a link elsewhere in the UI.
      * This listgrid is pulling data from a sql datasource.
      * The link the user clicks above passes meta-data to the listgrid about what record # or row # to show.
      * The listgrid is supposed to display the data and THEN scroll to the desired record #/row #.

      My initial approach was to use the DataArrivedHandler and then once the data has arrived, to simply scroll the grid to the desired row # using ListGrid.scrollToRow(<Row#>). Unfortunately, DataArrivedHandler is called BEFORE the grid is actually 'rendered' so the scrollToRow method call does nothing.

      I then looked into just about every other method on the ListGrid I could think of to see if one of them would fire once the grid was actually 'rendered':
      addVisibilityChangedHandler - Fires before grid is 'rendered' (and only after first draw)
      addViewStateChangedHandler - Fires before grid is 'rendered'
      addResizedHandler - Was getting desperate
      addFocusChangedHandler - Didn't meet my needs
      addFieldStateChangeHandler - Fired too early or not at all
      addDrawAreaChangedHandler - Thought this was the ONE, but no luck

      Ultimately, what I did was a HORRIBLE HACK and used a Timer. I really don't want to keep this in the production level product since there's no way to know for sure how long it may take the browser or client to render the grid. This DOES work because there's enough delay between the DataArrivedEvent and the grid completing 'rendering' to allow the scrollToRow method to work:
      Code:
      public void onDataArrived(DataArrivedEvent event) {
          if (_scrollToRow != -1) {
          	new Timer() {
          		
          		public void run() {
          			_gridLayout.getGrid().scrollToRow(_scrollToRow);
          			_scrollToRow = -1;
          		}
          		
          	}.schedule(500);
          }
      }
      So how do I handle this situation the 'correct' way. I'm sure others must have had a need to display/load a data-paged grid and then scroll to a specific row programmatically once the data was loaded? Using a timer is just a 'bad' idea I know it. Did I miss a listgrid event that I should use? Does one of the events above actually work and I just missed it?

      Thanks in advance.

      Comment


        #4
        Hello,

        I have the same problem !

        Is there no event to do that ?

        I want select a value in grid, It's ok when ever the table in dabase contains no much rows but when the table contains about 8000 rows it's doesn't work !

        Please respond

        Comment


          #5
          Jose -

          I never heard anything back from Isomorphic OR from any other forum users. For what it's worth, I'm still using the timer method I showed below.

          Ideally it would be nice to have a handler like: addGridRenderedHandler that would fire whenever the Grid is updated and visually finished rendering.

          Sadly, such a method doesn't exist.

          Comment


            #6
            That 's a very bad new ! (as always )

            Today also I was in front of a smartgwt bug !

            This one : http://forums.smartclient.com/showthread.php?t=20655

            (selectRecord(0) does not fire SelectionEvent )

            I have work 1 day on this because it's work on my pc and not in a other pc !

            We should always download the nightly build version ! And do some rework and validation.

            Otherwise I want always generate dynamic datasource ! I have done this with addDynamicdataSource API but a don't want to write a datasource file, I want a "In memory Datasource". I have post some message in this forum but no good responses has been provided !

            I write my datasources with an printWriter and the fields are always the same because the column name of the tables in databases is the same therefore I construct my own string and I write in a .ds.xml file with an printwriter !
            BUT I want have a way to ask what column (fields for DS) are in tables in database to have a dynamic string. I have see getFieldsXML() and some other methods. But no javadoc ^^

            Can you please post your full code ? Because I have do your scrollToRow() but event.getEndRow() give me always 75 so my grid is not completely loaded and I can't select a the newly created row with grid.selectRecord().

            Thanks,
            Last edited by jose.hello; 10 Mar 2012, 09:52.

            Comment


              #7
              Originally posted by jose.hello
              Can you please post your full code ? Because I have do your scrollToRow() but event.getEndRow() give me always 75 so my grid is not completely loaded and I can't select a the newly created row with grid.selectRecord().
              What exactly are you trying to do? Scroll the grid to the last record? Scroll grid to some user-specified record?

              Call grid.selectRecord() on a newly-loaded grid?

              In my code, I know what row the user is trying to view so when my data arrived handler is called, I wait for 500 seconds to let the grid load/draw all the data, and then I call scrollToRow. If you know what row the user is trying to select or scroll to, you could use my Timer implementation code above.

              Comment


                #8
                I'm currently use version 4.1 and I was facing the same issue, until I found addDrawHandler() method that seems working well, it fires and event when ListGrid is completely drawn. No javadoc was added in this version, so I can't tell what it exactly does, I have to base my considerations only on tests I did

                Comment


                  #9
                  DrawHandler fires when the ListGrid is drawn.

                  DataArrived is the correct approach and scrollToRow() has, for a very long time, automatically handled being called before data has rendered.

                  Comment


                    #10
                    Is there a reason that after it executes scrollToRow, it automatically scrolls back up to row 1 no matter what?

                    Comment

                    Working...
                    X