Announcement

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

    Cascade selection on TreeGrid using "load on demand" nodes

    Hi there,
    I have a TreeGrid containing a large amount of nodes, so we're using load on demand to expand each level of the tree as it's expanded.

    My problem is with cascading selection - we'd like to be able to select the top node of a section and have all children selected as well. This works fine for sections of the tree which have already been expanded, however nodes which have not been expanded have not yet loaded their children and so the children are not selected (even though their parents should have cascaded the selection downwards).

    I've thought of various ways to create this behaviour, such as expanding a node/the tree when it's selected, however I figure there may be some built-in way of handling this since it deals with commonly used features (load on demand, and cascade selection).

    Are there any techniques or workarounds for this?
    Last edited by khalk; 20 Oct 2010, 06:34.

    #2
    Hi Khalk,

    Probably the simplest option would be to have a dataArrived handler which checks for the parentNode being selected, and if it is calls 'selectRecords()' on the treeGrid to select the children as they are loaded.

    Comment


      #3
      Using Smart GWT: 3.0.

      Have the same issue as the original poster.

      Imagine I have this tree structure:

      Code:
      - A
         - Airplanes
              - 757
              - 320
         - Apples
      + B
      + C
      + D
      I have the tree set to load on demand because we have a lot of data in the database table feeding the TreeGrid view. Also have cascading select enabled in the TreeGrid (so if a user selects a folder, all the children under that folder are selected as well).

      When the application starts, the TreeGrid view shows the top-level parent folders:
      Code:
      + A
      + B
      + C
      + D
      The user needs to be able to select folder 'A' and all the children of A need to be selected as well. As the original poster mentions, selecting 'A' in the view above and then calling treeGrid.getSelectedRecords() will only return 'A' because none of the children nodes have been loaded because folder 'A' has not yet been expanded.

      What I need is for the user to be able to select 'A' and, without having to expand the tree, when I call treeGrid.getSelectedRecords() I get all the children under A due to the cascading select.

      I don't see anyway to provide this functionality right now. Ideally, there would be a method like treeGrid.loadChildren('A') which would asynchronously load the data and then provide a callback to let me know when it's loaded so I can then perform operations on 'A' and all it's children records. I could nto find such a method in Smart GWT's API.

      Is there some other way to provide this functionality? Call treeGrid.fetchData with custom criteria (parentId = <id of selected folder> OR NULL)?

      The second response doesn't make sense to me. It sounds like the responder says to add a DataArrived handler so that when the user does expand folder 'A' I can then select the loaded records but my user may never expand folder 'A' and I need to get all the child records.
      Last edited by chimpeenuts; 20 Jan 2012, 18:36.

      Comment


        #4
        It's tree.loadChildren(). Remember to use search, you basically guessed the API name, and loadChildren or any similar phrase hit its.

        Comment


          #5
          Originally posted by Isomorphic
          It's tree.loadChildren(). Remember to use search, you basically guessed the API name, and loadChildren or any similar phrase hit its.
          Thanks for the speedy response.

          So the TreeGrid view itself does not have a loadChildren method.

          TreeGrid.getData() or TreeGrid.getTree() does have a loadChildren method.

          However, when I read the documentation on that method it reads:

          Code:
          Load the children of a given node. This implementation does nothing other than mark the node as loaded
          This to me sounds like it marks the parent node, in my case 'A', as loaded...it doesn't actually fetch the children from the underlying datasource.

          Is this correct? Or is the documentation wrong?

          Thanks!

          Comment


            #6
            What you're seeing is doc for Tree, where that's true, whereas your load on demand TreeGrid has created a ResultTree, where loadChildren() does actually load the children.

            Comment

            Working...
            X