Vaadin表行内联编辑 [英] Vaadin Table row inline editing
本文介绍了Vaadin表行内联编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在vaadin中创建了一个表格,我在表格的每一行都有一个编辑按钮。我试过
I created a table in vaadin and I have an edit button for each row of the table.I tried
table.setEditable(true)
但这使整个表格可编辑。当我单击按钮编辑时,我只希望所选行可以编辑,如果可以自定义一些单元格示例复选框,下拉列表等任何建议?
but that makes the whole table editable. When I click the button edit I want only the selected row to be editable and if it is possible some cells to be customized example checkbox, dropdown etc. Any suggestions?
推荐答案
这是一个非常简单的例子:
Here is a very simplistic example:
final Table table = new Table();
table.setEditable(true);
table.setTableFieldFactory(new TableFieldFactory() {
private static final long serialVersionUID = 1L;
@Override
public Field<?> createField(Container container, Object itemId, Object propertyId, Component uiContext) {
if (itemId == table.getData()) {
return DefaultFieldFactory.get().createField(container, itemId, propertyId, uiContext);
}
return null;
}
});
table.addGeneratedColumn("", new ColumnGenerator() {
private static final long serialVersionUID = 1L;
@Override
public Object generateCell(Table source, final Object itemId, Object columnId) {
Button button = new Button(itemId == table.getData() ? "Save" : "Edit");
button.addClickListener(new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
if (table.getData() == null) {
// edit
table.setData(itemId);
table.refreshRowCache();
} else if (itemId == table.getData()) {
// save
table.setData(null);
// ...
table.refreshRowCache();
}
}
});
return button;
}
});
// ...
这篇关于Vaadin表行内联编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文