Announcement

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

    Moving tiles between two tilegrids

    Thanks in advanced for the help. I'm trying to use two tilegrids and drag tiles between them, but have not been successful.

    I placed the standard required information below. Please let me know if I've missed anything.

    Here is how to reproduce.
    Last dragged record stays highlighted and you can't move any but the last dropped in. Also when I inspect the component there are no tiles in the 2nd grid, only data.
    1. Drag all three tiles from the top grid to the bottom grid.
    2. Try to drag them back.

    Perhaps the only way to get tiles created is to use setData, is that correct? Seems like addData should provide similar functionality.
    1. Use the move button to move all the tiles to the bottom grid.
    2. Try to drag them back.

    OSX 10.11.6

    1.SmartClient Version: v11.0p_2016-10-31/Enterprise Deployment (built 2016-10-31) and SmartClient Version: v11.1p_2017-07-09/Enterprise Deployment (built 2017-07-09)
    2. Chrome 59.0.3071.115 (Official Build) (64-bit) - super dev mode and compiled mode
    3. n/a
    4. n/a
    5. n/a
    6.

    Code:
    import java.util.ArrayList;
    import java.util.List;
    
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.types.DragAppearance;
    import com.smartgwt.client.types.DragDataAction;
    import com.smartgwt.client.widgets.Button;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.DragCompleteEvent;
    import com.smartgwt.client.widgets.events.DragCompleteHandler;
    import com.smartgwt.client.widgets.events.DropCompleteEvent;
    import com.smartgwt.client.widgets.events.DropCompleteHandler;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.tile.TileGrid;
    import com.smartgwt.client.widgets.viewer.DetailViewerField;
    
    public class TestLayout extends VLayout {
    
    public TestLayout() {
    setHeight100();
    setWidth100();
    
    final TileGrid grid1 = new TileGrid();
    grid1.setCanReorderTiles(false);
    grid1.setCanDragTilesOut(true);
    grid1.setCanAcceptDrop(true);
    grid1.setPreventDuplicates(true);
    grid1.setTileDragAppearance(DragAppearance.TARGET);
    grid1.setDragDataAction(DragDataAction.MOVE);
    grid1.setFields(new DetailViewerField("id"), new DetailViewerField("title"));
    grid1.setData(createRecords(3).toArray(new Record[]{}));
    
    final TileGrid grid2 = new TileGrid();
    grid2.setCanAcceptDrop(true);
    grid2.setPreventDuplicates(true);
    grid2.setFields(new DetailViewerField("id"), new DetailViewerField("title"));
    grid2.setCanReorderTiles(true);
    grid2.setCanDragTilesOut(true);
    grid2.setDragDataAction(DragDataAction.MOVE);
    
    addMember(grid1);
    HLayout buttons = new HLayout();
    Button moveTiles = new Button("Move");
    moveTiles.addClickHandler(new ClickHandler() {
    
    @Override
    public void onClick(ClickEvent event) {
    Record[] data = grid1.getData();
    for (Record rec : data)
    {
    grid1.removeData(rec);
    grid2.addData(rec);
    }
    }
    });
    buttons.addMember(moveTiles);
    
    addMember(buttons);
    addMember(grid2);
    }
    
    private List<Record> createRecords(int num) {
    List<Record> records = new ArrayList<Record>();
    
    for (int i = 0; i < num; i++)
    {
    Record rec = new Record();
    rec.setAttribute("id", i);
    rec.setAttribute("title", "r" + i);
    records.add(rec);
    }
    return records;
    }
    }
    Last edited by awpirl; 24 Jul 2017, 05:27. Reason: formatting

    #2
    Please see the docs for how preventDuplicates behaves in the absence of a DataSource - it's probably not a behavior you want, and is the cause of some of these weird effects.

    Either turn off preventDuplicates or introduce a DataSource so that duplicates can really be detected. If you still have issues, first make sure you are testing with the latest patched build (see SmartClient.com/builds) and post a revised test case here.

    Comment

    Working...
    X