我正在使用 Ext Js 开发一个应用程序,但我遇到了一个问题,在我的一个视图中,用户能够动态添加新列,并且在网格中,第一个 Ext 组件是一个行编号器,它在添加用户时枚举我的行它。但是,随着行的添加,“rownumberer”的第一列一起增长,如下所示。谁能给我一个见解?谢谢!
编码:
var store = Ext.getStore('store');
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
var contador = 0;
Ext.define('Grid', {
extend : 'Ext.grid.Panel',
title: 'Grid',
store: 'StoreTemp',
columns: [
{
xtype: 'rownumberer'
},{
header : "Data Type",
dataIndex : 'nome',
flex : 0.8,
editor:'textfield'
}],
dockedItems : [ {
xtype : 'toolbar',
items : [ {
xtype: 'button',
tooltip: 'Click here to set data type on axis Y',
id : 'buttonTipoDado',
icon : Webapp.icon('edit.png'),
iconAlign : 'top',
handler : function() {
var gridView = Ext.ComponentQuery.query('gridpanel')[1];
Ext.Msg.prompt('Alert', 'Insert data type: ', function(
btn, text) {
if (btn == 'ok') {
gridView.getView().getHeaderAtIndex(1).setText(text);
var botao = Ext.getCmp('buttonTipoDado');
botao.setDisabled(true);
} else {
Ext.Msg.alert('Alert', 'Insert type!');
}
gridView.getView().refresh();
});
}
}, {
xtype: 'button'
icon : Webapp.icon('add1.png'),
iconAlign : 'top',
handler : function() {
var gridView = Ext.ComponentQuery.query('gridpanel')[1];
grid = gridView.headerCt;
if(grid.getGridColumns().length >= 1){
var column = Ext.create('Ext.grid.column.Column', {text : contador, editor: {xtype: 'textfield', flex: 0.5}});
gridView.headerCt.insert(gridView.columns.length, column);
var botao = Ext.getCmp('buttonRemoverColuna');
botao.setDisabled(false);
}
contador++;
}
}, {
xtype: 'button',
icon : Webapp.icon('cancel.png'),
iconAlign : 'top',
id : 'buttonRemoverColuna',
handler : function() {
var gridView = Ext.ComponentQuery.query('gridpanel')[1];
gridView = gridView.headerCt;
var botao = Ext.getCmp('buttonRemoverColuna');
if(gridView.getGridColumns().length == 2){
botao.setDisabled(true);
contador = 0;
}
else{
gridView = gridView.remove(gridView.getGridColumns().length - 1);
}
}
}, {
xtype: 'button',
icon : Webapp.icon('add1.png'),
iconAlign : 'top',
handler: function(){
var gridView = Ext.ComponentQuery.query('gridpanel')[1];
grid = gridView.getView();
grid.insert(0, new Ext.create('Model'));
rowEditing.startEdit(0, 0);
gridView.getView().refresh();
}
}, {
xtype: 'button'
icon : Webapp.icon('cancel.png'),
iconAlign : 'top',
handler: function(){
store.removeAt(0);
}
}]
} ],
plugins : [ rowEditing ]
});