简体   繁体   English

对于GWT Java FlexTable,如何在值更改时获取选定的行号

[英]For a GWT java FlexTable how do I get the selected row number on value change

I want to store the GWT FlexTable row number that contains a date when that date is changed. 我想存储GWT FlexTable行号,其中包含该日期更改时的日期。 The code is: 代码是:

//Add change handler for the task completion date.
dateCompletion.addValueChangeHandler(new ValueChangeHandler<java.util.Date>() {
    public void onValueChange(ValueChangeEvent<java.util.Date> event) {

        //TODO currentRow = flexAwardDescription.getRowIndex();
        //Display all YM who have not completed this task.
        AsyncCallback<List<YouthMember>> callback = new YMWithoutAwardHandler<List<YouthMember>>(CubBulkAward3View.this);
        rpc.getYMWithoutAwardList(ymAwardDetails.getad_Id(), callback);
    }
});

I have found an answer for click event; 我找到了点击事件的答案; however, not for change event. 但是,不用于更改事件。

Please check my answer here: Gwt getCellForEvent flexTable 请在这里检查我的答案: Gwt getCellForEvent flexTable

There's no obvious way to do it, what you can do is 没有明显的方法,您可以做的是

  1. Get event source 获取事件源
  2. Cast it to widget 投射到小部件
  3. Get it's Element via .getElement() then use getParent() to get Cell, and getParent() one more time to get row element. 得到它通过的元素.getElement()然后使用getParent()获取细胞,和getParent()更多的时间来获得行元素。

You can get it's index then, comparing it to rows from rowFormatter in a loop. 然后,您可以获取它的索引,并将其与循环中rowFormatter的行进行比较。

The work around I came up with is to capture row number on the click event (as you must first click before you can change) and then use this row number if a change event occurs. 我想到的解决方法是捕获click事件的行号(因为必须先单击才能更改),然后在发生更改事件时使用此行号。

//Get the row number of the row selected to display the names below it.
                flexAwardDescription.addClickHandler(new ClickHandler() { 
                    public void onClick(ClickEvent event) {  
                         currentRow = flexAwardDescription.getCellForEvent(event).getRowIndex();
                    } 
                }); 

                //Add change handler for the task completion date.
                dateCompletion.addValueChangeHandler(new ValueChangeHandler<java.util.Date>() {
                    public void onValueChange(ValueChangeEvent<java.util.Date> event) {
                        //Check if this is the completion row
                        if (ymAwardDetails.getad_Description().matches("(.*)Completed:(.*)")) {
                            groupCompleted = "C";
                        }else{
                            groupCompleted = "S";
                        }
                        awardDescriptionID = ymAwardDetails.getad_Id();
                        //Display all YM who have not completed this task.
                        AsyncCallback<List<YouthMember>> callback = new YMWithoutAwardHandler<List<YouthMember>>(CubBulkAward3View.this);
                        rpc.getYMWithoutAwardList(ymAwardDetails.getad_Id(), accountId, callback);
                    }
                }); 

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

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