问题描述
我已经使用Google Web Toolkit创建了一个CellTable.我刚刚开始使用它,而我对此的了解非常少.但是,我在搜索有关如何在CellTable标题中创建复选框的教程或代码示例,但我发现的所有内容我都不理解或不起作用.
到目前为止,我已经获得了以下代码来为复选框和普通表创建一个Column,该普通表与CellTable的Google教程基本相同:
Column< Contact,Boolean>checkColumn = new Column< Contact,Boolean>(new CheckboxCell(true,false)){@Overridepublic Boolean getValue(Contact contact){返回null;}};table.addColumn(checkColumn,SafeHtmlUtils.fromSafeConstant(< br/&";)));table.setColumnWidth(checkColumn,40,Unit.PX);
现在,我正在搜索要在标题中添加复选框的代码,以及如何使其选中或取消选中所有复选框.
感谢您的时间.
来自
我正在使用选择模型和数据列表提供程序来完成选择魔术.可能并不适合所有人.
这是我的自定义标头:
公共最终类CheckboxHeader扩展了Header {私有最终MultiSelectionModel selectionModel;私有的最终ListDataProvider提供程序;公共CheckboxHeader(MultiSelectionModel selectionModel,ListDataProvider提供程序){超级(新CheckboxCell());this.selectionModel = selectionModel;this.provider =提供程序;}@Overridepublic Boolean getValue(){boolean allItemsSelected = selectionModel.getSelectedSet().size()==提供程序.getList().size();返回allItemsSelected;}@Override公共无效onBrowserEvent(上下文上下文,元素elem,NativeEvent事件){InputElement输入= elem.getFirstChild().cast();布尔值isChecked = input.isChecked();对于(TYPE元素:provider.getList()){selectionModel.setSelected(element,isChecked);}}}
I´ve created an CellTable with the Google Web Toolkit.I just started using it and my knowledge about it is very small...However I was searching for a tutorial or just a code example of how to create a checkbox in the CellTable header but everythin I´ve found I didn´t understand or it didn´t worked.
So far I´ve got this code to create a Column for checkboxes and a normal table mostly the same as the Google tutorial for a CellTable:
Column<Contact, Boolean> checkColumn = new Column<Contact, Boolean>(
new CheckboxCell(true, false)) {
@Override
public Boolean getValue(Contact contact) {
return null;
}
};
table.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
table.setColumnWidth(checkColumn, 40, Unit.PX);
Now I´m searching for the code to add a checkbox to the header and how to make it check or uncheck all checkboxes.
Thanks for your time.
From my blog post:
Here is a simple column header that selects/ de-selects all rows in a table. When all rows are checked, the header becomes checked automatically. Clicking the checkbox in the header causes either to select or de-select all rows.
I am using the selection model and the data list provider to do the selection magic. It may not work for everyone.
And here is my custom header:
public final class CheckboxHeader extends Header {
private final MultiSelectionModel selectionModel;
private final ListDataProvider provider;
public CheckboxHeader(MultiSelectionModel selectionModel,
ListDataProvider provider) {
super(new CheckboxCell());
this.selectionModel = selectionModel;
this.provider = provider;
}
@Override
public Boolean getValue() {
boolean allItemsSelected = selectionModel.getSelectedSet().size() == provider
.getList().size();
return allItemsSelected;
}
@Override
public void onBrowserEvent(Context context, Element elem, NativeEvent event) {
InputElement input = elem.getFirstChild().cast();
Boolean isChecked = input.isChecked();
for (TYPE element : provider.getList()) {
selectionModel.setSelected(element, isChecked);
}
}
}
这篇关于GWT标头复选框可以选中/取消选中表中的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!