Unanswered: GXT 2.2.5, drag-n-drop listener and comparator TreeStore priority
I use GXT2.2.5
I need to do some business logic with a drag-n-drop in the TreeStore. This action changes the value on what the Comparator is based on. The problem is that the sort is automatically called before the drag-and-drop event listner.
1- user drag n drop an item in the tree (this changes the order);
2- the TreeStore Comparator is called;
3- the DNDListener is called;
I wish that the Comparator was called after my DNDListener so the tree would be sort the right way.
Can you provide an example of what you are describing? The DNDListener has many handlers, some of which are clearly called before the drop is complete. Additionally, you haven't made it clear what you add the DNDListener to - both the source and the target fire those events, the source first, then the target.
Remember too that events are used to find out that something has happened, not that it is about to happen. In the case of DNDListener.onDragDrop, you are being informed that the DnD operation was successful - at this time you might choose to save data back to the server. If this method went off before the drop was finished and you saved data, the change would not properly be stored. As such, you probably want to be customizing the DropTarget.onDragDrop details (overriding it and adding your details before calling super, for example) or if using TreePanelDropTarget, perhaps you'll want to override handleAppendDrop or handleInsertDrop.
Another option could be to modify the comparator after the drop is complete and re-apply the sort. This would be more expensive, but might not matter much in your particular use case.
I got rid of the comparator being automatically handled by the store. I call the sort when the dragNDrop event finishes. Would have been nice that the sort events were handled after all other events but that's not the case. In other word, don't use (store.setModelComparer) if you expect to sort after a dragNDrop. Use (tree.getStore().sort) when ever you need it.