【问题标题】:CellList keep selected Cells selected?CellList 保持选中的单元格被选中?
【发布时间】:2013-12-15 12:03:27
【问题描述】:

我使用完美的MGWT CellList

我有以下问题。如何让选定的单元格保持选中状态,以便在用户释放单元格后保持选中状态?

这是我的实现:

CellList<Item> myCellList = new CellList<Item>(new ItemCell());

我的 ItemCell 类:

public class ItemCell implements Cell<Item> {

    private static Template TEMPLATE = GWT.create(Template.class);

    public interface Template extends SafeHtmlTemplates {
        @SafeHtmlTemplates.Template("<div>{0}</div>")
        SafeHtml content(String cellContents);
    }

    @Override
    public void render(SafeHtmlBuilder safeHtmlBuilder, Item model) {
        SafeHtml content = TEMPLATE.content(model.getName());

        safeHtmlBuilder.append(content); 

    }

    @Override
    public boolean canBeSelected(Item model) {
        return true;
    }

}

我的物品类:

public class Item {

    private String name;

    public Item() {
        setName("");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

【问题讨论】:

  • 用户释放单元格究竟是什么意思?你要多选吗?如果是,只需使用多选处理程序
  • @我希望如果用户点击/单击一个单元格,它会保持选中状态。我该怎么做?

标签: java javascript html gwt mgwt


【解决方案1】:

您想要的是选择处理程序。如果要单选使用 SingleSelectionHandler,如果要多选使用 MultiSelectionHandler, 示例代码:

 SelectionModel<Item> selectionModel = new SingleSelectionModel<Item>();
    cellList.setSelectionModel(selectionModel);

如果你想在选择上做任何事情,你可以在这里做

selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
      public void onSelectionChange(SelectionChangeEvent event) {
                   /** Do your thing here **/
           selectionModel.getSelectedObject();  //for single Selection
           selectionModel.getSelectedSet(); //for multiple Selection   
      }
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多