Announcement

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

    How to move nodes in a treeGrid

    I want to programatically move a node in a treeGrid to THE SAME PARENT but to another position. With other words, I want to *reorder* the children of a parent programatically.

    This doesn't work:
    tree.move(node, parent, newPosition);

    Since, as the docs say, it is intended to move the node to ANOTHER parent. So, nothing happens. How to achieve this ?

    Using smartgwt 5.0p 28.06 power.

    #2
    Hi edulid,

    did you already see the EE-#persistent_reorderable_TreeGrid-sample? I'm using the ListGrid version of it and it's working like a charm.

    Best regards
    Blama

    Comment


      #3
      Yes, but I don't want the records to be draggable, but I have a button which moves them up/down. So I need to do this programatically, not just making them draggable.

      Comment


        #4
        Right now, you'd need to reload or replace the entire set of children to change the order.

        We'll look at allowing a call to move() which just changes order within the same parent, but this would be a 5.1 change at best.

        Note that this would apply only in limited circumstances: not to a sorted tree, and not to a tree using fetchMode:"paged", for example.

        Comment


          #5
          Originally posted by edulid View Post
          I want to programatically move a node in a treeGrid to THE SAME PARENT but to another position. With other words, I want to *reorder* the children of a parent programatically.

          This doesn't work:
          tree.move(node, parent, newPosition);

          Since, as the docs say, it is intended to move the node to ANOTHER parent. So, nothing happens. How to achieve this ?

          Using smartgwt 5.0p 28.06 power.
          The existing Tree.move() does fail on certain corner cases, but should work right now in simple cases. Can you provide some sample code where you're seeing it not work as intended? This will allow us to verify that we've actually addressed your problem.

          Comment


            #6
            Originally posted by Isomorphic View Post
            Note that this would apply only in limited circumstances: not to a sorted tree, and not to a tree using fetchMode:"paged", for example.
            I actually need this for a sorted tree. My idea is the following: The tree is displayed sorted by some field "sortingField". The user wants to change the sorting in the DB (the sortingField), so he moves the children to the desired new positions. Then he presses a "save sorting" button, and the "sortingField" from all fields is actualized to the DB reflecting this new order. The "sortingField" ist just an integer.

            This would be something similar as the batch edit, just for the positions.

            I will try to make a testcase, but first please tell me if this would be applicable for a sorted tree in my case.

            Comment


              #7
              The issue here is that there are a lot of actions the user might take on the tree, like filtering or applying a new sort, where you might want to either keep or discard the temporary ordering.

              Most likely the simplest thing to do is to follow the pattern shown for the persistent reorderable TreeGrid sample, effectively immediately saving the sort order as far as the SmartGWT UI is concerned, but not actually committing the data to the original DB records until the user confirms.

              The layer of logic that maintains the temporary sort information could be either client-side (in a ResponseTransformer for example) or server-side.

              Comment


                #8
                Originally posted by Isomorphic View Post
                Most likely the simplest thing to do is to follow the pattern shown for the persistent reorderable TreeGrid sample
                Yes, this pattern would be what I need. Trying it, it works *only* if the treeGrid ist *not* initially sorted, i.e. if setSort() is not being called.
                If it is being called, nothing happens when trying to drag the records to the new position.

                Comment


                  #9
                  Not sure what you mean by this - when records are dragged to a new position, you need to actually save the updated field to the DataSource - that's what the sample shows. Once the TreeGrid sees that the field it is sorting by has been changed (via automatic DataSource cache synchronization), the updated sort direction is shown.

                  As we mentioned, although you need to save to the DataSource and report success, you need not store to the underlying DB (until later on).

                  Comment

                  Working...
                  X