Javascript 加载列时ExtJS阻止resizecolumn事件
我正在做一个ExtJS6.2项目。当网格中的列调整大小时,我需要执行一些操作。我认为正确的做法是调整列大小。问题是,由于这些列是从数据库动态加载的,因此每次向网格中添加新列时都会触发此事件,我想阻止它。我的意思是,我只需要在加载每个列时触发此事件 我试图设置一个名为lFirstInit的标志,一旦从数据库加载列,该标志将为false,但columnresize事件从一开始就一直被触发 请问,我该怎么做?谢谢 视图: 控制器Javascript 加载列时ExtJS阻止resizecolumn事件,javascript,extjs,Javascript,Extjs,我正在做一个ExtJS6.2项目。当网格中的列调整大小时,我需要执行一些操作。我认为正确的做法是调整列大小。问题是,由于这些列是从数据库动态加载的,因此每次向网格中添加新列时都会触发此事件,我想阻止它。我的意思是,我只需要在加载每个列时触发此事件 我试图设置一个名为lFirstInit的标志,一旦从数据库加载列,该标志将为false,但columnresize事件从一开始就一直被触发 请问,我该怎么做?谢谢 视图: 控制器 我们最终放弃了“columnresize”方法。我们认为点击“关闭”按钮
我们最终放弃了“columnresize”方法。我们认为点击“关闭”按钮执行thos操作更可靠。然而,我要感谢你的建议,尤其是在我将其标记为所选答案之前将其删除的人,他在下面发布了答案。这是他/她发布的代码:
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa@simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart@simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer@simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge@simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
width: 400,
renderTo: Ext.getBody(),
listeners: {
columnresize: function(ct, column, width, eOpts){
if(ct.containsFocus){// It will true when we resize column.
alert('resize');
console.log(`${column.text} Column resized`);
}
}
}
});
您是否计算过UI上会呈现多少列?如果是,则可以将渲染列数与实际列数进行比较。如果你能演示一些伪代码,我就可以编写它。你能在网格视图的刷新侦听器中以编程方式添加columnresize侦听器吗?
Ext.define('App.view.TMainBrowseGridViewController', {
extend: 'Ext.app.ViewController',
alias: 'controller.TMainBrowseGrid',
onGridpanelColumnResize: function (component, column, width, eOpts) {
// THINGS TO DO...
}
});
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa@simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart@simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer@simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge@simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
width: 400,
renderTo: Ext.getBody(),
listeners: {
columnresize: function(ct, column, width, eOpts){
if(ct.containsFocus){// It will true when we resize column.
alert('resize');
console.log(`${column.text} Column resized`);
}
}
}
});