简体   繁体   English

vaadin 8网格行索引中的问题

[英]Issue in vaadin 8 Grid row index

I am migrating my project from vaadin 7 to vaadin 8. As Table is removed. 我将项目从vaadin 7迁移到vaadin 8。 so I am replacing it with grid. 所以我用网格替换它。 previously I was fetching the row ids for multiple selection like this: 以前我是这样提取多个选择的行ID的:

  Set<Object> itemIds = table.getValue();
  for(Object lItem : itemIds){
      Integer lId = Integer.parseInt(lItem.toString());
  }

But in vaadin 8 grid there is a itemclick listener that provide rowindex only if we click on any item and on click of any checkbox for selection it does not return anything, as checkboxes only works with selection listener. 但是在vaadin 8网格中,只有当我们单击任何项​​目并且单击任何要选择的复选框时,itemclick侦听器才提供rowindex,因为该复选框仅适用于选择侦听器,因此它不返回任何内容。 see code below: 参见下面的代码:

  lGrd.addItemClickListener(new ItemClickListener<Employee>() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void itemClick(ItemClick<Employee> event) {

            if(lGrd.getSelectionModel().isSelected(event.getItem())){
                if(!lSelection.contains(event.getRowIndex())){
                    lSelection.add(event.getRowIndex());
                }
            }else if(lSelection.contains(event.getRowIndex())){
                lSelection.remove(event.getRowIndex());
            }

            Notification.show(lSelection.toString() + " Selected Employees Row Id");
        }
    });

Also using selection listener it does not return any row index like as in itemclicklistener 同样使用选择侦听器,它不会像itemclicklistener中那样返回任何行索引

  lGrd.addSelectionListener(new SelectionListener<Employee>() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void selectionChange(SelectionEvent<Employee> event) {
            Set<Employee> lSet = event.getAllSelectedItems();
            for(Employee emp : lSet){
                //how to fetch row id here
            }
        });

It provides selected items but no row index. 它提供选定的项目,但不提供行索引。 How to fetch Employee Row index here. 如何在此处获取员工行索引。 Also if I want any column data. 另外,如果我想要任何列数据。 How to fetch it? 如何取得?

Since Framework version 8.4.0 (release notes) the Grid.ItemClick event (Grid.ItemClick doc) also contains the row index information of the clicked item. 从Framework版本8.4.0(发行说明)开始,Grid.ItemClick事件(Grid.ItemClick doc)还包含单击项的行索引信息。

before that we had a ugly workaround :( 在此之前,我们有一个丑陋的解决方法:(

we hat 我们讨厌

private List items; 私人清单项目; private Grid grid; 私人网格 as a Class Fields. 作为类字段。

in the initialisation method we filled the List with items and had 在初始化方法中,我们用项目填充了List并具有

grid.setITems(items); grid.setITems(items);

onclick we allways had the item from click Event earlier something ugly like (Item) event.getSource().getValue() i think with modern Vaadin the Event is parametrised, so we simply get event.getValue() 在onclick上,我们总是从click Event那里获得了该项目,这有点像(Item)event.getSource()。getValue(),我认为对于现代Vaadin来说,该Event是参数化的,因此我们只需获取event.getValue()

then we used items.indexOF(event .. get Value ..); 然后我们使用items.indexOF(event .. get Value ..);

so i am VERY thankfull, that since Vaadin 8.4 we can refactor this :) ! 因此,我非常感谢,自Vaadin 8.4以来,我们可以重构此:)! ! !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM