GridPanel无法在Internet Explorer中获取行索引

时间:2011-12-21 06:28:53

标签: internet-explorer gwt

当我尝试点击GridPanel中的一行时,我正在接收其他人的项目并且仅在INTERNET EXPLORER中遇到错误。我能够在表上正确显示数据,但是当我点击该行时,想要获取行索引来执行其他一些操作,我在IE 7和8上获得行索引的“null”。在FF上没有问题,Chrome,Safari。

消息:'0'为空或不是对象 行:10 查尔:1601 代码:0 URI:http://mysite.com/Proj/js/ext/adapter/yui/ext-yui-adapter.js

消息:'0'为空或不是对象 行:10 查尔:1601 代码:0 URI:http://mysite.com/Proj/js/ext/adapter/yui/ext-yui-adapter.js

这是在gridPanel中生成值的代码:

grid.getEl().mask("Searching for codes, please wait...", true);
    AsyncCallback<LinkedHashMap<Long, Map>> acb = new AsyncCallback<LinkedHashMap<Long, Map>>() {

        public void onFailure(Throwable caught) {
             grid.getEl().unmask();
            MessageBox.alert("Failed :" + caught.getMessage());
        }

        public void onSuccess(LinkedHashMap<Long, Map> result) {

            Set key = result.entrySet();
            Iterator it = key.iterator();
             grid.setVisible(true);

            while (it.hasNext()) {
                Map.Entry en = (Map.Entry) it.next();
                Map m = (Map) en.getValue();
                String code = m.get("code").toString();
                try {

                    Date activationDate = new Date(Long.parseLong(m.get("activationtime").toString()));
                    Date deactivationDate = new Date(Long.parseLong(m.get("deactivationtime").toString()));
                    String actDateF = DateTimeFormat.getFormat("dd-MM-yyyy KK:mm:ss").format(activationDate);
                    String deactDateF = DateTimeFormat.getFormat("dd-MM-yyyy KK:mm:ss").format(deactivationDate);

                    Object[] obj = new Object[]{
                        actDateF,
                        deactDateF,
                        code
                    };


                    Record record = recordDef.createRecord(obj);
                     grid.getStore().add(record);

                } catch (Exception e) {

                    codeNotReading.add(code);
                    codeNotReading.add(e.getMessage());

                }
            }

            grid.getView().refresh();
            grid.getEl().unmask();
            if (codeNotReading.size() > 0) {
                MessageBox.alert(" \n Following code(s) cann't be added.  : " + codeNotReading.toString());
            }

        }
    };

以及获取行索引的代码:

grid.addGridCellListener(new GridCellListenerAdapter() {

      @Override
        public void onCellDblClick(GridPanel grid, int rowIndex, int colIndex, EventObject e) {                
            MessageBox.alert("Row "+rowIndex);
        }
    });

1 个答案:

答案 0 :(得分:0)

有时,您可以双击GridPanel并在行的单元格外部进行双击。所以rowIndex将为null。我建议你在第MessageBox.alert("Row "+rowIndex);行放一个断点,检查rowIndex是否为负数或为空。

如果为负或为null,则将 onCellDblClick 的代码更改为以下内容:

if (rowIndex != null && rowIndex >= 0) {
    MessageBox.alert("Row "+rowIndex);
}