javascript 单击单元格时如何防止extjs网格滚动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6061392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to prevent extjs grid from scrolling when clicking on a cell?
提问by user465374
I am currently using the grid component with Extjs 4 based on the editable grid example. I would like to have a link associated with each cell so that when I click on a cell it takes me to another page. However, when there is a vertical scroll that is trigered on the page when clicking on the link.
我目前正在使用基于可编辑网格示例的 Extjs 4 的网格组件。我想有一个与每个单元格关联的链接,这样当我单击一个单元格时,它会将我带到另一个页面。但是,当单击链接时在页面上触发垂直滚动时。
e.g. try reducing the size of http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/cell-editing.html, the first click on the grid scrolls the page so that the grid is on the center and the event is swallowed. You have to click again to have the cellclick event registered. This only happens in IE (I am using version 8). The good news is that this does not happen with other browsers, could this be a bug and is there a way to prevent this first scrolling action from happening?
例如尝试减小http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/cell-editing.html的大小,第一次点击网格会滚动页面,使网格位于中心和事件被吞没。您必须再次单击才能注册 cellclick 事件。这仅发生在 IE 中(我使用的是版本 8)。好消息是其他浏览器不会发生这种情况,这可能是一个错误,有没有办法阻止第一个滚动操作发生?
Thanks
谢谢
回答by thomasf1
I′ve had the same problem and found a solution on the Sencha discussion board.
我遇到了同样的问题,并在 Sencha 讨论板上找到了解决方案。
Adding this code did work for me:
添加此代码对我有用:
selModel: Ext.create('Ext.selection.Model', { listeners: {} }),
More information: http://www.sencha.com/forum/showthread.php?133983-How-to-prevent-extjs-grid-from-scrolling-when-clicking-on-a-cell
更多信息:http: //www.sencha.com/forum/showthread.php?133983-How-to-prevent-extjs-grid-from-scrolling-when-clicking-on-a-cell
回答by Max Bogdanov
Try out this patch
试试这个补丁
Ext.override(Ext.selection.RowModel, {
onRowMouseDown: function(view, record, item, index, e) {
//IE fix: set focus to the first DIV in selected row
Ext.get(item).down('div').focus();
if (!this.allowRightMouseSelection(e)) {
return;
}
this.selectWithEvent(record, e);
}
});
回答by vanderwyst
I had this same problem with ExtJS 4.2 today and the earlier solutions were not working for me, using this config on the gridpanel handled the problem fully:
我今天在 ExtJS 4.2 上遇到了同样的问题,早期的解决方案对我不起作用,在 gridpanel 上使用这个配置完全解决了这个问题:
viewConfig: {
focusRow: Ext.emptyFn
}
For example:
例如:
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
viewConfig: {
focusRow: Ext.emptyFn
}
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'phone' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
回答by Gerhard
this could be similar to this problem: In IE7 the first click on a grid causes an ExtJS Ext.grid.GridPanel to jump to the top of the pagetry position:relative;zoom:1 on the container around the grid to give it hasLayout
这可能与此问题类似:在 IE7 中,第一次单击网格会导致 ExtJS Ext.grid.GridPanel 跳转到页面顶部尝试 position:relative;zoom:1 在网格周围的容器上为其提供 hasLayout