Javascript extjs网格编辑器前进到下一列
我正在尝试制作一个网格编辑器,在第一列中键入5个字符后,它将自动前进到下一列。我已经把我认为是正确的代码放在一起,但是所选列一直跳回第一列并清除输入的数据 以下是我正在使用的网格:Javascript extjs网格编辑器前进到下一列,javascript,extjs,Javascript,Extjs,我正在尝试制作一个网格编辑器,在第一列中键入5个字符后,它将自动前进到下一列。我已经把我认为是正确的代码放在一起,但是所选列一直跳回第一列并清除输入的数据 以下是我正在使用的网格: Ext.create('Ext.grid.Panel', { title: 'idNumbers', store: Ext.data.StoreManager.lookup('priceStore'), plugins: [Ext.create('Ext.grid.plugin.RowEdit
Ext.create('Ext.grid.Panel', {
title: 'idNumbers',
store: Ext.data.StoreManager.lookup('priceStore'),
plugins: [Ext.create('Ext.grid.plugin.RowEditing',
{
clicksToEdit: 1,
pluginId: 'idNumberGridEditor'
})],
columns: [
{
header: 'Name',
dataIndex: 'idNumber',
editor: {
allowBlank: false,
xtype: 'combobox',
store: Ext.data.StoreManager.lookup('idNumberStore'),
displayField: 'idNumber',
valueField: 'idNumber',
typeAhead: true,
allowBlank: false,
forceSelection: true,
enableKeyEvents: true,
listeners: {
keyup: function(combo, e, eOpts) {
if(combo.getValue().length==5)
{
//move to next control
if(!this.nowFive)
{
editPlugin = this.up().editingPlugin;
curRow = editPlugin.context.rowIdx;
curCol = editPlugin.context.colIdx;
editPlugin.startEdit(curRow, curCol + 1);
this.nowFive = true;
}
}
else
{
this.nowFive = false;
}
}
}
}
},
{
header: 'Phone',
dataIndex: 'price',
editor: {
allowBlank: false,
xtype: 'numberfield'
}
}
],
height: 200,
width: 400,
renderTo: Ext.getBody(),
listeners: {
afterrender: function() {
console.log(this);
//this.editor.startEdit(1,1);
}
}
});
下面是一个完整的示例:将重置编辑状态(它将与或一起使用。您希望在这里只关注下一个字段,这样插件将正确处理编辑状态
以下是你的听众在这种精神下的改写():
最后,正如Akori所说,如果您将
forceSelection
设置为true,组合值将被强制设置为商店中已经存在的值,这可能不是您想要的值。我不认为fiddle是正确的…修复了jsfiddle的链接为什么您要设置forceSelection:true并希望人们自动访问t输入5个字符后,下一个字段是什么?它是一个或另一个,但不是两个,您希望人们从提供的值(组合框)中选择一些内容,或者您让他们键入他们想要的任何内容(textfield)很好,我不知道RowEditor的getEditor函数。这个解决方案似乎可行,但是,我将在代码中对当前列进行硬编码,因为实际上我将有两个字段需要一个接一个地前进。除非我手动更新RowEditor上下文,否则当前列将不会更新到正确的位置b但是如果我手动更新它,如果用户重新编辑第一个字段,它可能会跳到错误的列。
keyup: function(combo, e, eOpts) {
if(combo.getValue().length==5) {
//move to next control
if(!this.nowFive) {
var editPlugin = this.up().editingPlugin,
editor = editPlugin.getEditor(), // Ext.grid.RowEditor
curCol = editPlugin.context.colIdx,
currentField = editor.getEditor(curCol),
nextField = editor.getEditor(curCol + 1);
if (currentField) {
// ensure the combo is collapsed when the field is blurred
currentField.triggerBlur();
}
if (nextField) {
// startEdit will reset the edit state... What we need
// is simply to focus the field, the value will be
// updated when the user clicks the "update" button.
nextField.focus();
}
this.nowFive = true;
}
} else {
this.nowFive = false;
}
}