Announcement

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

    Reorder within TreeGrid using Drag'n'drop

    Slowly getting to know SmartGWT the questions keep arising (I hope someone will have the time to write at manual some day).

    I'm trying to add drag'n'drop reordering on a TreeGrid. I've called setCanReorderRecords(true) + setDragDataAction(DragDataAction.MOVE) and everything is looking fine.

    I'm using a custom DataSource based on the GwtRpcDataSource described elsewhere in this forum.

    After dragging a node, my DataSource is called (update) and now I assume I need to tell the server that the 'order' field of two or more records has changed. But how do I know what has happened? The update request itself doesn't seem to carry that information?

    I tried adding a FolderDropHandler to the TreeGrid to determine what is happening. Then I guess I would update the 'order' field on all affected records, so that the update in it's turn would know what to do.

    But I'm still not sure exactly what has happend in the event. I get the new index of the node, but how do I know which record is beeing moved?

    I tried calling folderDropEvent.getNodes() but this results in a ClassCastExecption : ListGridRecord cannot be cast to TreeNode?!

    It feels like I'm working agains the framework here. So could someone please tell me what the correct approach is?

    Thanks in advance,
    Christian

    P.S. I have tried to find the answer on the forum, but can't seem to.

    #2
    So I do this in a more custom way for my app, but this should help. If you have a addFolderDropHandler() then you can tell easily what is going on by event.getNodes() (these are the one or more nodes being moved) and event.getFolder() (this is the 'new' parent). Assuming in your datasource you have a single field per each node that gives the parent value, you only need to update this parent value with the ID of event.getFolder(). There is no need to know what the previous parent was just the new parent.

    Hope this helps. My code is pretty simple but works perfectly:
    Code:
    for each node {
        accountsService.reparentTreeNode(event.getNodes()  [i].getAttributeAsInt("id"), event.getFolder().getAttributeAsInt("id"),
    new AsyncCallback<Void>() {
        @Override
        public void onFailure(Throwable caught) {//TODO}
    
        @Override
        public void onSuccess(Void result) {//TODO}
        });
    }

    Comment


      #3
      Hi Svjard,

      Thanks for your reply. You're solution is close to what I was expecting. BUT notice that I'm using a TreeGrid and that it throws a ClassCastException when calling folderDropEvent.getNodes()?! This seems to be a fault in the framework?

      Would any of the developers care to comment on this?

      Comment


        #4
        This isn't the fault of the framework, again I am using a TreeGrid also and that ListGridRecord at the minimum has an ID field with it. So get the ID attribute and then TreeGrid.getTree().findById(myID) for whatever. Again why you need the TreeNode I am not sure, it really shouldn't be needed from your description.

        Comment


          #5
          Ahhr... Sorry, I just realised my mistake. My Datasource was making instances of ListGridRecord instead of TreeNode's, thus the ClassCastException.

          Thanks again!

          Comment

          Working...
          X