是否有使用 Vaadin ClickListener 事件方法获取行号的方法? [英] Is there a method to get row number with a method of Vaadin ClickListener's event?

查看:34
本文介绍了是否有使用 Vaadin ClickListener 事件方法获取行号的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个四列的网格.最后一个包含一个图像,我通过向其 ImageRenderer 添加一个 ClickListener 使其可点击.我的目标是访问该行(或其所有元素)以删除该行.

I have a Grid with four columns. The last one contains an image, which I make clickable by adding a ClickListener to its ImageRenderer. My goal is to access the row (or all of its elements) to delete the row.

  Grid<Row> grid = new Grid<>();
 
    ...
        
        grid.addColumn(row -> row.getValue("NAME")).setCaption("NAME");
        
        grid.addColumn(row -> row.getValue("PHONE")).setCaption("PHONE");
        
        grid.addColumn(row -> row.getValue("EMAIL")).setCaption("EMAIL");
        
        ImageRenderer ir = new ImageRenderer();
            ir.addClickListener(
                    event -> {
                        System.out.println(event.getItem());
                        
                    }); 
        grid.addColumn(row -> row.getValue("icon_delete"), ir).setCaption("");

我的问题是关于 ImageRenderer 的 ClickListener: 事件有一个名为 getItem() 的方法 - 但我还没有找到一种方法来获取包含单击项的行号.有没有办法做到这一点?

My question is one concerning the ImageRenderer’s ClickListener: event has a method called getItem() - yet I have not found a way to get the number of the row containing the clicked item. Is there a way to achieve that?

推荐答案

对于任何遇到此问题但对行号有其他需求的人:

For any people who come to this question with some other need for the row number:

Grid 不知道行号,您需要询问数据提供者或用于为数据提供者提供数据的任何内容.那个东西可能是一个数据库或一个简单的 ArrayList,你用来生成一些虚拟数据.数据提供者的实现通常也没有查询行号的直接方法,但是如果数据提供者不是懒惰的,您可以获取整个项目列表,将其放入一个 ArrayList,然后向 ArraList 询问 indexOf.对于惰性数据,您最好查询原始来源.

Grid doesn't know the row numbers, you need to ask the data provider or whatever you use for providing data for the data provider. That something might be a database or a simple ArrayList that you used to generate some dummy data. Data provider implementations don't usually have a direct method for querying the row numbers either, but if the data provider isn't lazy, you could get the entire item list, put it into an ArrayList, and ask the ArraList for the indexOf. With lazy data you are probably better off querying the original source.

同样的这取决于您的实现"适用于是否有一种简单的方法可以访问任何可能影响显示顺序的潜在过滤器或比较器或 TreeGrid 项目的展开/折叠状态.您至少需要将数据提供者转换为它的实际实现类,因为通用 DataProvider 接口不提供这些方法.

The same 'it depends on your implementation' goes for whether there is an easy way to access any potential filters or comparators or TreeGrid items' expand/collapse status that might affect the displayed order. You will at the very least need to cast the data provider into its actual implementation class because the generic DataProvider interface doesn't provide those methods.

在大多数情况下,行号与 Grid 的需求无关.

For the most part row numbers are not relevant information for Grid's needs.

这篇关于是否有使用 Vaadin ClickListener 事件方法获取行号的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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