Announcement

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

    Best practices question - initializing ListGrid fields

    Hi,
    We are setting properties of ListGrid fields in 2 places:
    1. Define number of field properties in DS
    2. Add/override more runtime based on a context while building the grid.
    In SmartGWT 3.1 we did:
    1. If grid layout is not modified and saved by a user - read the datasource fields and set them on the grid via setFields
    2. If layout exists - use grid.setViewState to set saved layout
    3. In both cases get fields using grid.getFields and then iterate over them and set runtime settings.

    As we're evaluating 6.1 for an upgrade, one of the changes from 3.1 we found is grid.getFields (and grid.getAllFields) is null after setViewState is called.
    I am planning to change our approach and always first set fields from datasource, then call setViewState(if necessary) and then modify fields from getFields()
    However, I am not sure this is the best way to go about it - seems redundant.
    I am assuming this is a fairly typical problem people face - is there a best practices approach?

    Thanks!



    Last edited by smartiro; 30 Oct 2017, 07:48.

    #2
    There is no need to get the fields from the DataSource and set them on the grid, this happens automatically - see the DataBinding chapter of the QuickStart Guide.

    As far as getting null from getFields(), this seems to indicate your call is too early. You haven't done anything to the grid which would cause it to initialize, such as fetching data or causing it to draw. You could call completeCreation() to force initialization, or wait for it via adding a CanvasInitHandler.

    Comment


      #3
      Thanks for quick response, Isomorphic.

      If we don't set fields from DataSource on the grid we'll need to draw the grid before modifying its fields and causing/needing a redraw.
      I was trying to avoid that assuming it would be more costly performance-wise than setting fields on the grid and modifying them before drawing for the first time.
      But maybe my assumption is wrong?

      Also, there seem to be a difference in behavior of setViewState between 3.1 (where it seemed to be initializing the grid) and 6.1 (where it's not). Is this done on purpose or it's a bug?

      Thanks!

      Comment


        #4
        We just suggested calling completeCreation(), not drawing.

        You are asking about a very very old version - a lot of APIs were adjusted so that they did not force initialization to happen unnecessarily early, as this can create duplicate work with later API calls or cause them to be disallowed (since some properties can't be changed after initialization). setViewState() could have been one of these, but again, you already have a solution.

        Comment


          #5
          Thanks again and one more (hopefully final) question - when I do completeCreation() right after setViewState() I still have getFields() return an empty list.
          I am assuming this is because it's an async process, so I need to listen to some creation completion event?

          Thanks!

          Comment

          Working...
          X