我有一个带有cellediting插件的gridpanel,并且有很多网格标题
(至少使网格显示为水平滚动条)...
这是DEMO ...
我的网格中有一个错误,尝试编辑其中一个错误,然后按Tab键导航到 header15 ..
网格没有滚动到我正在编辑的位置,...
这是一个错误?我们在forum寻找这个,但没有运气..
,有一种方法scrollByDeltaX
,
但如何从活动编辑器中了解delta?
答案 0 :(得分:0)
剪短,try demo first:)
(太自由了,想要你的赏金,请奖励我!)
有趣的是,我的回答在4.0.7上运行得很好,但它在4.0.2a上不起作用!毫无头绪,我检查了4.0.2a
的来源,并且震惊地看到了这一点:
在src/panel/Table.js
(4.0.2a)
/**
* Scrolls the TablePanel by deltaY
* @param {Number} deltaY
*/
scrollByDeltaY: function(deltaY) {
var verticalScroller = this.getVerticalScroller();
if (verticalScroller) {
verticalScroller.scrollByDeltaY(deltaY);
}
},
/**
* Scrolls the TablePanel by deltaX
* @param {Number} deltaY
*/
scrollByDeltaX: function(deltaX) {
var horizontalScroller = this.getVerticalScroller();
if (horizontalScroller) {
horizontalScroller.scrollByDeltaX(deltaX);
}
},
注意到什么?签出函数scrollByDeltaX
!它的编码错误(在4.0.7中修复)!!!这显然不会有任何视觉反馈。它要求垂直滚动条进行deltaX滚动。怎么会这样?
无论如何,要解决此问题相当容易,以防您不想升级到4.0.7。 Afaik 4.0.7有大量从4.0.6继承的错误,它打破了我的项目与那个怪异的屏蔽问题。
以下是我的工作答案,我希望你会感激。基本上我修改了onEditorTab
方法并创建了一个事件挂钩,因此您的grid
可以挂钩,并在触发标签时执行scrollByDeltaX
。
我不太确定如何最左/右最左侧滚动,所以我的代码中出现了一个有趣的Infinity
。
以下是示例: DEMO (请记住尝试SHIFT + TAB)
/**
* Customized Row Selection Model which will
* fires "editortab" event when an tabbing occurs
*/
Ext.define('NS.RowModel', {
extend: 'Ext.selection.RowModel',
//False to wrap to next row when you tab
//to the end of a row
preventWrap: false,
initComponent: function() {
/**
* @event editortab
* Fires when editor is tabbed
* @param {RowModel} rowModel this rowmodel
* @param {Editor} edt The editor
* @param {string} dir The direction of the tab (left or right)
* @param {Event} e The event object
*/
this.addEvents('editortab');
this.callParent();
},
//memorizing which is the last context
lastEditorContext: null,
onEditorTab: function(edt, e) {
//Part of this code is from the original onEditorTab in
//src/selection/RowModel.js line 416
var me = this,
view = me.views[0],
record = edt.getActiveRecord(),
header = edt.getActiveColumn(),
position = view.getPosition(record, header),
direction = e.shiftKey ? 'left' : 'right',
newPosition = view.walkCells(position, direction, e, this.preventWrap);
//we store the last context, so we know whether the
//context has changed or not
me.lastEditorContext = edt.context;
//if there is new position, edit; else, complete the edit.
if (newPosition) {
edt.startEditByPosition(newPosition);
}else{
edt.completeEdit();
}
//If context doesn't change, we try to walk
//to the next one until we find a new edit box (context changed)
while (me.lastEditorContext === edt.context && newPosition) {
newPosition = view.walkCells(newPosition, direction, e, this.preventWrap);
if (newPosition) {
edt.startEditByPosition(newPosition);
}
}
//Fires the event
this.fireEvent('editortab', this, edt, direction, e);
}
});
/**
* Customized Editor Grid to support tabbing
*/
Ext.define('NS.EditorGrid', {
extend: 'Ext.grid.Panel',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})],
selModel: Ext.create('NS.RowModel', {
listeners: {
editortab: {
fn: me.onEditorTab,
scope: me
}
}
})
});
me.callParent();
},
onEditorTab: function(sel, edt, dir, e) {
var lastRow = sel.lastEditorContext.rowIdx,
newRow = edt.context.rowIdx,
deltaX = 0;
//Let's calculate deltaX first
//if row changed, we reset the cells to the left most or right most
if (lastRow != newRow) {
deltaX = lastRow < newRow ? -Infinity : Infinity;
}else{
//else, do deltax :)
deltaX = edt.context.column.width * (dir == 'right' ? 1 : -1);
}
//If you are using 4.0.2a, use this. They have typo in
//src/panel/Table.js, line 1133
var horizontalScroller = this.getHorizontalScroller();
if (horizontalScroller) horizontalScroller.scrollByDeltaX(deltaX);
//But if you are running 4.0.7, this is fine. Use this:
//this.scrollByDeltaX(deltaX);
}
});
//-------------------------------------------------
//Everything below remains :)
Ext.onReady(function() {
var storeSr=Ext.create('Ext.data.ArrayStore', {
fields: ["KD_SR","NM_SR"]
});
//load data
var tmpd=[];
for (i=1;i<=15;i++){
tmpd.push([i,"nm "+i]);
}
storeSr.loadData(tmpd);
//create column
col=[]
col.push({header: "Kode", dataIndex: 'KD_SR'});
for (j=1;j<=15;j++){
col.push({
header: "Header"+j,
width:100,
dataIndex: 'NM_SR',
editor:{xtype:"textfield"}
});
}
var gridSr = Ext.create('NS.EditorGrid', {
height: 200,
width: 500,
store: storeSr,
columns: col
});
//create window
var winEditSR=Ext.create("Ext.Window",{
title:"Sub Rayon",
autoWidth : true,
autoHeight : true,
autoShow:true,
border : false,
modal : true,
items : [gridSr]
});
});
我仍然想知道是否有更好的解决方案......也许使用列(header
)的x
来确定滚动条的scrollLeft
,但这会非常生涩...