簡體   English   中英

GWT僅針對表行而不是標題添加雙擊處理程序

[英]GWT add double click handler only for table rows, not header

我們通過擴展com.google.gwt.user.client.ui.Composite在我們的應用程序中實現了GWT自定義表格窗口小部件。 該表上有一個雙擊處理程序,它會打開一個彈出窗口以編輯所選記錄。

// 'table' is our implementation

final NoSelectionModel<OurCustomDTOClass> editSelectedRowModel = new NoSelectionModel<OurCustomDTOClass>();
table.getTable().setSelectionModel(editSelectedRowModel, DefaultSelectionEventManager.createBlacklistManager(0));
table.addDomHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(final DoubleClickEvent event) {
            // code to open the popup to edit the record        
            // this popup must be opened only if the user selects the rows and NOT the header   
        }
}, DoubleClickEvent.getType());

只是為了獲得更多信息,該表被繪制為th (對於表標題)和tr (對於表行)。

我們需要做的是避免雙擊動作,如果用戶雙擊表頭。 我已經搜索了SO和其他參考資料,但是還沒有運氣。

任何有用的指針,表示贊賞。 謝謝。

您可以嘗試檢查事件的目標:

Element e = Element.as(event.getNativeEvent().getEventTarget());
if (e.getTagName().toLowerCase().equals("td")) {
    // do something
}

或者,您可以將窗口小部件拆分為兩個獨立的窗口小部件-一個用於標題,另一個用於表主體。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM