简体   繁体   English

如何将ToDeltaX gridpanel滚动到活动编辑器(cellediting)?

[英]how to scrollToDeltaX gridpanel to the active editor(cellediting)?

i have a gridpanel with cellediting plugin, and with a lot of grid header 我有一个带有cellediting插件的GridPanel,并且有很多Grid Header
(at least make the grid shown it horizontal scrollbar)... (至少使网格显示为水平滚动条)...
here is the DEMO ... 这是演示 ...

there is a bug in my grid, try to edit one of the collumn, and then press tab key to navigate to header15 .. the grid didn't scroll to where i am editing,... 我的网格中有一个错误,请尝试编辑其中一个列,然后按Tab键导航到header15 ..网格未滚动到我正在编辑的位置,...
is it a bug?? 这是一个错误吗? a have looking for this at their forum , but no luck.. 一个已经在他们的论坛上寻找这个,但是没有运气..

so, how to fix it?? 那么,如何解决呢?
how to make my grid scroll to the active editor?? 如何使我的网格滚动到活动编辑器?

from docs, there is a method scrollByDeltaX , 从文档,有一个方法scrollByDeltaX
but how to know the delta from active editor?? 但是如何从活动编辑器中了解增量?

Cut it short, try demo first :) 简而言之, 请先尝试演示 :)

(Too free, and wanted your bounty, please award me!) (太免费了,想要得到赏金,请奖励我!)

Funny that my answer works just nice on 4.0.7, but it doesn't work on 4.0.2a! 有趣的是我的答案在4.0.7上很好用,但在4.0.2a上却没有用! Out of no clue, I checked the source of 4.0.2a , and shockingly saw this: 毫无头绪,我检查了4.0.2a的源,并震惊地看到了这一点:

In src/panel/Table.js (4.0.2a) src/panel/Table.jssrc/panel/Table.js )中

/**
 * 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);
    }
},

Noticed anything? 注意到什么了吗? Checkout the function scrollByDeltaX ! 签出功能scrollByDeltaX It's coded wrongly (fixed in 4.0.7)!!! 代码编码错误(已在4.0.7中修复)!!! And this will obviously wouldn't have any visual feedback. 这显然不会有任何视觉反馈。 It is asking the vertical scrollbar to do a deltaX scrolling. 它要求垂直滚动条进行deltaX滚动。 How can it be? 怎么可能?

Anyway, to fix this problem is rather easy, in case you do not want to upgrade to 4.0.7. 无论如何,如果您不想升级到4.0.7,修复此问题相当容易。 Afaik 4.0.7 has tons of bugs inherited from 4.0.6, and it breaks my project with that freaking masking issue. Afaik 4.0.7具有从4.0.6继承的大量错误,它以那个令人毛骨悚然的掩蔽问题破坏了我的项目。

Below is my working answer, and I hope you'll appreciate it. 以下是我的工作答案,希望您能满意。 Basically I have modified the onEditorTab method and created an event hook, so your grid can hook onto it, and do the scrollByDeltaX when tabbing is triggered. 基本上,我已经修改了onEditorTab方法并创建了一个事件挂钩,因此您的grid可以挂钩到该grid上,并在触发制表键时执行scrollByDeltaX

I'm not too sure how to do a scroll left most/right most, so a funny Infinity has been used in my code out of laziness. 我不太确定如何最左/最右滚动,因此出于懒惰,我的代码中使用了一个有趣的Infinity

Here is the example: DEMO (Remember to try out SHIFT+TAB too) 这是示例: 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]
    }); 
});

I still wondering if there might be a better solution... perhaps using column ( header )'s x to determine scroller's scrollLeft , but that will be pretty jerky... 我仍然想知道是否有更好的解决方案...也许使用column( header )的x来确定滚动条的scrollLeft ,但是那会很生涩...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM