2 Replies Latest reply on Feb 26, 2013 10:56 AM by Michael Hirsch

    Knowing when a widget is present in the DOM

    Michael Hirsch Newbie

      I am trying to create a wrapper for SlickGrid (https://github.com/mleibman/SlickGrid/wiki) which is a pretty nice javascript table or spreadsheet widget.  What I have looks good and is quite featureful, but I'm having trouble instantiating it.

       

      If I try to load slickgrid in the @PostConstruct, it doesn't (usually) work.  The problem is that slickgrid looks for its parent element in the dom at creation time.  Apparently, during the postconstruct the parent is not yet in the DOM.  My parent is a Composite that contains a ScrollPanel, which will be the parent of the slickgrid.  The problem is that I don't know when the ScrollPanel is actually in the DOM so that slickgrid can load.

       

      Here is the code that instantiates the grid:

      <verbatim>

          public void createGrid() {

              if (grid != null) return;

             

              String parentId = parent.getElement().getId();

              boolean parentIsPresent = DOM.getElementById(parentId) != null;

             

              if (parentIsPresent) {

                  Columns gridColumns = new Columns();

                  for (FormattedColumn<R> col : columns) {

                      Column gridColumn = Column.create(col.getId(), col.getName());

                      gridColumns.addColumn(gridColumn);

                  }

                 

                  GridData data = makeData(rows);

                 

                  grid = Grid.create(parentId, gridColumns, data, options);

              }

          }

      </verbatim>

      As you can see, I can check for whether the parent is present in the DOM by querying the DOM.  What I don't know how to do is wait for the parent to be present.  I'm guessing that I need some kind of callback, or the ability to run something when the event loop is idle, but I really don't know.

       

      Is there a way to for the DOM to be complete before running my code?

       

      Thanks,

       

      Michael