gpt4 book ai didi

ExtJS 4 : Excel-style keyboard navigation in an editable Grid

转载 作者:行者123 更新时间:2023-12-05 00:00:27 25 4
gpt4 key购买 nike

使用 ExtJS 4 我想创建一个网格,用户将在其中输入一长串数字。我希望用户能够通过按“Enter”完成一个单元格的编辑,然后自动移动到下面的单元格并开始编辑。

Ext.grid.plugin.CellEditing 似乎可以很好地用于编辑,但我找不到检测和处理 keyUp 事件的方法。

我尝试使用带有以下代码的“编辑”事件来解决这个问题:

selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners: {
edit: function (editor, e, eOpts) {
// If the event is fired by pressing "Enter", the column and row associated with event will
// be the same as the currently selected row and column

if (e.grid.selModel.position.column == e.colIdx && e.grid.selModel.position.row == e.rowIdx){

// Check if we are in the final row
if (e.rowIdx+1 == e.grid.getStore().getTotalCount()){
return true;
}

editor.startEditByPosition({row: e.rowIdx+1, column: e.colIdx});
return false;
}
}
}
})
],

这种方法的问题在于,如果用户开始编辑单元格,然后单击网格外的 GUI 元素,则编辑事件不会将其与按下的“Enter”键区分开来。这可以解决吗?

也许我应该尝试实现自定义 SelectionModel ?如何开始采用这种方法?

最佳答案

类似 this ???
编辑时尝试使用 tab , shift + tab , enter , 和 shift + enter
我所做的是覆盖 celleditingselection.rowmodel
实际上,我也有过类似的 question和你。和@Lionel Chan 帮我解决。
我上面的解决方案是基于他的想法。

注意:仅适用于 Extjs 4.0.7

编辑(如果我的 jsfiddle 坏了,这里是覆盖)

Ext.override(Ext.grid.plugin.CellEditing,{
onSpecialKey: function(ed, field, e) {
var grid = this.grid,sm;
if (e.getKey() === e.TAB) {
e.stopEvent();
sm = grid.getSelectionModel();
if (sm.onEditorTab)sm.onEditorTab(this, e);
}else if(e.getKey() === e.ENTER){
e.stopEvent();
sm = grid.getSelectionModel();
if (sm.onEditorEnter)sm.onEditorEnter(this, e);
}
}
});

Ext.override(Ext.selection.RowModel, {
lastId:null,
onEditorTab: function(ep, e) {
var me = this,
view = me.view,
record = ep.getActiveRecord(),
header = ep.getActiveColumn(),
position = view.getPosition(record, header),
direction = e.shiftKey ? 'left' : 'right',
newPosition = view.walkCells(position, direction, e, false),
newId=newPosition.row,
grid=view.up('gridpanel');

if (me.lastId!=newId && me.lastId!=null){
deltaX = me.lastId<newId? -Infinity : Infinity;
header=grid.headerCt.getHeaderAtIndex(newPosition.column);
if(header){
while(!header.getEditor()){
newPosition= view.walkCells(newPosition,direction, e, false);
header=grid.headerCt.getHeaderAtIndex(newPosition.column);
}
}
}else{
deltaX = ep.context.column.width * (direction== 'right' ? 1 : -1);
}
grid.scrollByDeltaX(deltaX);
me.lastId=newPosition.row;
Ext.defer(function(){
if (newPosition)ep.startEditByPosition(newPosition);
else ep.completeEdit();
}, 100);
},
onEditorEnter:function(ep,e){
var me = this,
view = me.view,
record = ep.getActiveRecord(),
header = ep.getActiveColumn(),
position = view.getPosition(record, header),
direction = e.shiftKey ? 'up' : 'down',
newPosition = view.walkCells(position, direction, e, false),
newId=newPosition.row,
grid=view.up('gridpanel');

deltaY=20 * (direction== 'down' ? 1 : -1);
grid.scrollByDeltaY(deltaY);
me.lastId=newPosition.row;
Ext.defer(function(){
if (newPosition)ep.startEditByPosition(newPosition);
else ep.completeEdit();
}, 100);
}
});

关于ExtJS 4 : Excel-style keyboard navigation in an editable Grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10179047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com