在Vaadin 7中以编程方式在Grid中选择一行? [英] Programmatically select a row in Grid in Vaadin 7?

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

问题描述

Vaadin 7.5.3,我们可以通过调用 Grid::getSelectedRows .

In the Grid widget in Vaadin 7.5.3, we can determine the current selection of rows by calling SelectionEvent::getSelected or Grid::getSelectedRows.

那么我们如何通过编程设置?

So how do we set the selection programmatically?

推荐答案

网格类没有声明此方法,但是您仍然可以通过编程方式进行操作.我不会争论它是否是错误.首先,您需要知道什么是SelectionMode.然后,您可以选择一行(或几行):

While that's true that official documentation for Grid class doesn't have this method stated, still you can do it programmatically. I won't argue whether it's a bug or not. Firstly you need to know what is your SelectionMode. Then you can select a row (or rows):

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    Customer c = new Customer(1);
    container = new BeanItemContainer<>(Customer.class, Arrays.asList(c, new Customer(2)));
    grid = new Grid(container);
    grid.setSelectionMode(SelectionMode.SINGLE);
    SingleSelectionModel m  = (SingleSelectionModel) grid.getSelectionModel();
    m.select(c);
    layout.addComponents(grid);
    setContent(layout);
}

这篇关于在Vaadin 7中以编程方式在Grid中选择一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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