Announcement

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

    DynamicForm initial scroll to item

    We're using SmartGWT 4.1 power version:
    SmartClient Version: v9.1p_2014-10-03/PowerEdition Deployment (built 2014-10-03)

    Our implementation has an overridden ListGrid and DynamicForm sharing the same datasource. The fields of DynamicForm are set via setFields() to preserve the grid's field presentation.

    In the Grid upon SelectionUpdatedEvent we call editSelectedData(grid).
    If a cell is double-clicked within that Grid row a CellDoubleClickEvent is also called, resulting in a call to a method to scroll to the corresponding item in the Dynamicform and select its value;

    Code:
        public void focusInItem(String focusField ) {
            TextItem item = (TextItem)getItem(focusField);
            if (item != null && isVisible()) {
                scrollTo(item.getLeft(), item.getTop());
                item.focusInItem();
                item.selectValue();
            }
        }

    The problem is that the first time this is called, it appears the items are not 'drawn' yet. In the line checking for an item != null, this condition is true, however, item.isDrawn() returns null and item.getLeft() and item.getTop() both return 0.

    On subsequent ListGrid cell double clicks this works fine, as the items have been drawn, and getLeft() and getTop() return valid positions. The Dynamicform scrolls to the correct field, and selects its value.

    My question is how can I determine that the items in my DynamicForm have been drawn and ready to be scrolled to.. I've tried adding an ItemChangeHandler, VisibilityChangedHandler, FocusChangedHandler to the form, but none of these guarantees the items are in a state where they can be scrolled to following the form's creation. e.g. item.isDrawn() != null and getLeft()/getTop() return the fields coordinates..

    #2
    From your description, it sounds like you're asking for a draw notification handler (you already have a way to check for the current drawn state via 'isDrawn()').
    You could add a 'drawHandler' to your Form itself to determine if the form is drawn.
    Or if the problem is that a setItems() call has occurred, but the form has not yet redrawn to show the items, you could check form.isDirty() and explicitly call a synchronous form.redraw() to force an immediate redraw.

    If this doesn't give you enough to get things going, we'll probably need to see the problem in action so we have a clearer picture of exactly what the "unready state" you're in is / how best to detect it.

    Regards
    Isomorphic Software

    Comment


      #3
      Thanks, forcing a redraw if the item.isDrawn() is null, then recalling our focusInItem(String) method via a drawHandler, partially worked.

      The field double-clicked in the ListGrid is now scrolled to in the form, However, the item.selectValue() doesn't select on the first execution of that method.

      Subseqeunt double-clicks result in the desired behavior, the form scrolls to the item and the value of the item is selected.

      Is there a handler/scenario available to check/trigger before calling item.selectValue()?
      Last edited by ewilliams; 21 Oct 2014, 08:09.

      Comment


        #4
        This sort of focus / selection manipulation the tend to be a slightly tricky area due to the fact that natively browser behavior varies across browsers, and in I.E., native focus and blur events are asynchronously fired after page focus has moved to an item, while in other browsers they are not.

        You may be able to get the behavior you need by simply setting 'selectOnFocus' to true on your item/form and either having the form be autoFocus true, or explicitly putting focus in the item via a focusInItem call.
        Alternatively, this may be one of those rare cases where it makes sense to literally use a hardcoded delay (of zero, or something very small like 200ms) to ensure the focus/select call occurs in a separate thread from the call to draw / setItems on the form.

        If neither of those suggestions get things working for you, please show us a little runnable test case which demonstrates the issue (ie a simple EntryPoint class we could run, which simply defines a ListGrid and a form and has a similar double-click handler on the grid to focus / select in the form as in your application). This will allow us to see exactly what you are attempting to do, and why it isn't working.
        Also please be sure to let us know which browsers / OS you're seeing the problem on

        Regards
        Isomorphic Software

        Comment


          #5
          Thank You! The timer solution worked. Used 100ms and only in the draw handler, so it's only delayed on the initial open/draw of the form.

          Comment

          Working...
          X