1

我需要锁定网格中的一些列。这是我的网格配置代码:

Ext.define('Crm.view.tables.baseTable', {
extend: 'Ext.grid.Panel',
alias : 'widget.baseTable',
columnLines: true,
initComponent: function(){
var that = this;
var $this = that;

this.selType = 'checkboxmodel',
this.selModel = {
    allowDeselect: true,
    mode: "MULTI"
};

this.plugins = [
    new Ext.grid.plugin.CellEditing({
            clicksToEdit: 2
        }),
        {
            ptype: 'bufferedrenderer',
            numFromEdge: 8,
            trailingBufferZone: 10,
            leadingBufferZone: 10
        }
];

var filters = {
        ftype: 'filters',
        encode: true,
        local: true

    };

this.features = [filters];

    var columns = [
        new Ext.grid.RowNumberer(),
        {
            header   : 'ID',
            dataIndex: 'id',
            locked   : true,
            filterable: true,
            width    : 30
        },{
            header  : 'ФИО',
            width   : 100,
            dataIndex: 'name',
            filterable: true,
            filter: {
                type: 'string'
            },
            editor: 'textfield'
        },{
            header   : 'Телефон',
            dataIndex: 'phone',
            filterable: true,
            width    : 75,
            editor: 'textfield'
        },{
            header   : 'Email',
            dataIndex: 'email',
            filterable: true,
            width    : 90,
            editor: 'textfield'
        }
    ];

this.columns = columns

var tbar = [{
        text: 'Обновить',
        handler: function(){
            $this.getStore().reload();
        }
},'-',{
    text: 'Очистить фильтр',
    handler: function () {
        that.filters.clearFilters();
    }
},'-']

this.tbar = tbar;

this.callParent();

}
});

但我收到一个错误:

Uncaught TypeError: Cannot call method 'on' of undefined ext-all-debug.js:115013

当我bufferedrenderer从配置中删除插件时,锁定的列有效。问题是什么?感谢您的回答!

4

1 回答 1

1

这适用于 EXTJS 4.2.1。

以下代码是“Ext.data.grid.plugin.Bufferedrenderer”的初始化函数当您对网格使用锁定功能时,ExtJs 用“Ext.grid.locking.View”包装 grid.view。然后 init 函数尝试查找 grid.view 的属性,这些属性不能通过包装器获得。所以我在初始化函数中添加了几行(在下面用“//用grid.View替换locking.View”找到它)然后它解决了这个问题。

只需通过以下 init 函数扩展“Ext.data.grid.plugin.Bufferedrenderer”来创建类。

Martin.P - EMH 咨询公司。

init: function(grid) {
    var me = this,
        view = grid.view,
        viewListeners = {
            scroll: {
                fn: me.onViewScroll,
                element: 'el',
                scope: me
            },
            boxready: me.onViewResize,
            resize: me.onViewResize,
            refresh: me.onViewRefresh,
            scope: me,
            destroyable: true
        };

    //********************************************************************
    // replace locking.View with grid.View  - hayangae@gmail.com
    if (view.isLockingView){
        view = view.getViewForColumn();
    }
    //********************************************************************

    // If we are using default row heights, then do not sync row heights for efficiency
    if (!me.variableRowHeight && grid.ownerLockable) {
        grid.ownerLockable.syncRowHeight = false;
    }

    // If we are going to be handling a NodeStore then it's driven by node addition and removal, *not* refreshing.
    // The view overrides required above change the view's onAdd and onRemove behaviour to call onDataRefresh when necessary.
    if (grid.isTree || grid.ownerLockable && grid.ownerLockable.isTree) {
        view.blockRefresh = false;
        view.loadMask = true;
    }
    if (view.positionBody) {
        viewListeners.refresh = me.onViewRefresh;
    }
    me.grid = grid;
    me.view = view;
    view.bufferedRenderer = me;
    view.preserveScrollOnRefresh = true;

    me.bindStore(view.getStore());
    view.getViewRange = function() {
        return me.getViewRange();
    };

    me.position = 0;

    me.gridListeners = grid.on('reconfigure', me.onReconfigure, me);
    me.viewListeners = view.on(viewListeners);
},
于 2013-10-31T19:54:08.257 回答