阻止网格面板的键盘多重选择(prevent keyboard multiselect for gridpanels)

编程入门 行业动态 更新时间:2024-10-28 08:23:28
阻止网格面板的键盘多重选择(prevent keyboard multiselect for gridpanels)

我想要一个选择网格,起初我没有包含任何选择模型配置,因为这是默认设置 。 这适用于鼠标选择但如果我键SHIFT + END它选择所有记录(或PAGE UP , HOME或END具有类似的效果)。

然后,如果不重新加载网格,则无法取消选择所选记录(除非我想要一个配置了allowDeselect: true的网格 - 我不这样做)。

认为这是ExtJS文档关于默认值的问题,然后我明确地将网格面板配置为SINGLE选择,但仍然存在问题。

在这里检查了他们的一些示例网格,它们都有相同的问题 - 任何单个选择网格都会阻止鼠标多选,但可以使用shift键和HOME , END , PAGE UP或PAGE DOWN 。 然后就不可能取消选择记录。

似乎是框架中的一个错误,我将提交报告,但由于网格是最常用的组件之一,我认为有人有一个解决方法。

无奈之下,我也尝试全局收听keypress并停止活动,但这甚至都没有。 例如,这将记录到控制台,但事件仍会运行:

Ext.getDoc().on('keypress', function(event, target) { var key = event.getKey(); // do not allow multiple grid selection if (event.shiftKey && ( key == event.PAGE_UP || key == event.PAGE_DOWN || key == event.HOME || key == event.END)) { console.log('unsuccessfully trying to stop the event!'); event.stopEvent(); event.stopPropagation(); event.shiftKey = false; return false; } });

编辑:

我不想用enableKeyNav: false禁用所有键盘导航enableKeyNav: false我只是不想用键盘多选。

I want a single select grid, at first I did not include any selection model configuration because that is the default. This works fine for mouse selections but if I key SHIFT + END it selects all records (or PAGE UP, HOME or END has a similar effect).

The selected records are then impossible to deselect without reloading the grid (unless I wanted a grid that is configured with allowDeselect: true - which I don't).

Thinking that this was a problem with the ExtJS docs about the default, I then configured the gridpanel with SINGLE select explicitly but still had the problem.

I checked out some of their example grids here, and they all have the same problem - any single select grid will prevent mouse multiselection but can be multiselected with the shift key and HOME, END, PAGE UP or PAGE DOWN. And it is then impossible to deselect the records.

Seems to be a bug in the framework and I will file a report, but since grids are one of the most commonly used components I assumed someone has a workaround for this.

In desperation I also tried listening to keypress globally and stopping the event but that won't even do it. For example, this will log to the console but the event runs anyway:

Ext.getDoc().on('keypress', function(event, target) { var key = event.getKey(); // do not allow multiple grid selection if (event.shiftKey && ( key == event.PAGE_UP || key == event.PAGE_DOWN || key == event.HOME || key == event.END)) { console.log('unsuccessfully trying to stop the event!'); event.stopEvent(); event.stopPropagation(); event.shiftKey = false; return false; } });

EDIT:

I do not want to disable all keyboard navigation with enableKeyNav: false I just don't want to multiselect with the keyboard.

最满意答案

您可以使用:

selModel: { enableKeyNav: false },

在网格配置中。 但这对我来说意外的选择模型行为......

更新

作为一个非常简单的版本:

selModel: { selectRange: function() { return false; } },

You can use:

selModel: { enableKeyNav: false },

in grid config. But it was unexpected selection model behavior for me...

Update

As a very simple version:

selModel: { selectRange: function() { return false; } },

更多推荐

本文发布于:2023-07-30 21:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340280.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   面板   键盘   prevent   multiselect

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!