GWT CellTable以编程方式选择CheckBoxCell [英] GWT CellTable programmatically select CheckBoxCell

查看:196
本文介绍了GWT CellTable以编程方式选择CheckBoxCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cellTable与CheckBoxCell列。我想做的是在单元格外面有一组按钮,让用户自动检查/取消选中不同的元素集(例如,检查所有/取消选中所有,但我想有更复杂的规则)。



我不明白是如何访问元素(我想通过row / col值???),并获取/设置值。

解决方案

任何人都可以帮我找出解决方法吗?假设你想要的是将复选框绑定到选择,并轻松地以编程方式选择一组项目(细微:选择项目,这将导致复选框被选中,而不是复选框),你会使用 MultiSelectionModel



您可以在 http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTable ,即:

  final MultiSelectionModel< ContactInfo> selectionModel = new MultiSelectionModel< ContactInfo>(
ContactDatabase.ContactInfo.KEY_PROVIDER);
cellTable.setSelectionModel(selectionModel,
DefaultSelectionEventManager。< ContactInfo> createCheckboxManager());
...
列< ContactInfo,Boolean> checkColumn = new Column< ContactInfo,Boolean>(
new CheckboxCell(true,false)){
@Override
public Boolean getValue(ContactInfo object){
//获取值从选择模型。
return selectionModel.isSelected(object);
}
};
cellTable.addColumn(checkColumn,SafeHtmlUtils.fromSafeConstant(< br />));
cellTable.setColumnWidth(checkColumn,40,Unit.PX);

然后,要选择一个项目

  selectionModel.setSelected(item,true); 

,您可以类似地获取所有选定项目的集合 selectionModel.getSelectedSet ()


I've got a cellTable with a CheckBoxCell column. What I'm trying to do is to have a set of buttons outside the celltable which let the user to automatically check/uncheck a different set of elements (for example check all / uncheck all, but I'd like to have more complex rules).

What I don't understand is how to access the element (I suppose via row/col values ???) and get/set the value.

Can anyone help me to figure out how to resolve it?

解决方案

Assuming what you want is to bind the checkbox to "selection" and easily select a bunch of items programmatically (subtlety: select items, which will result in checkbox being checked, rather than checking boxes), you'll use a MultiSelectionModel.

You'll find sample code in http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTable, that is:

final MultiSelectionModel<ContactInfo> selectionModel = new MultiSelectionModel<ContactInfo>(
    ContactDatabase.ContactInfo.KEY_PROVIDER);
cellTable.setSelectionModel(selectionModel,
    DefaultSelectionEventManager.<ContactInfo> createCheckboxManager());
…
Column<ContactInfo, Boolean> checkColumn = new Column<ContactInfo, Boolean>(
    new CheckboxCell(true, false)) {
  @Override
  public Boolean getValue(ContactInfo object) {
    // Get the value from the selection model.
    return selectionModel.isSelected(object);
  }
};
cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
cellTable.setColumnWidth(checkColumn, 40, Unit.PX);

Then, to select an item (and have its checkbox checked automatically), you'll simply do:

selectionModel.setSelected(item, true);

and you can similarly get the set of all selected items with selectionModel.getSelectedSet().

这篇关于GWT CellTable以编程方式选择CheckBoxCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆