Ext grid超強力なダイナミック追加フィールド、カラム拡張
最近ずっとextを学んで私の好きなextの中国語のコミュニティをぶらぶらして、フォーラムの中で多くの人が聞くことを見ます:どのように1つのgridの列の招待状を動的に追加してあるいは削除して、そこで1つの拡張をして、みんなは見て、私は悪くないと思います!
使用方法:
この記事は、次のように掲載されています.
http://www.17ext.com/showtopic-1759.aspx、コードを直接実行するように割り当てましたよ!
grid.addColumn('C');//C列追加、空データ
grid.addColumn({name: 'D', defaultValue: 'D'}, {header: 'D', dataIndex: 'D'});//D列追加、Dデータあり
grid.removeColumn('B');//前のB列を削除する
再び突き落とす
http://www.17ext.com/
Ext.override(Ext.data.Store,{
addField: function(field){
if(typeof field == 'string'){
field = {name: field};
}
this.recordType.prototype.fields.replace(field);
if(typeof field.defaultValue != 'undefined'){
this.each(function(r){
if(typeof r.data[field.name] == 'undefined'){
r.data[field.name] = field.defaultValue;
}
});
}
},
removeField: function(name){
this.recordType.prototype.fields.removeKey(name);
this.each(function(r){
delete r.data[name];
});
}
});
Ext.override(Ext.grid.ColumnModel,{
addColumn: function(column, colIndex){
if(typeof column == 'string'){
column = {header: column, dataIndex: column};
}
var config = this.config;
this.config = [];
if(typeof colIndex == 'number'){
config.splice(colIndex, 0, column);
}else{
colIndex = config.push(column);
}
this.setConfig(config);
return colIndex;
},
removeColumn: function(colIndex){
var config = this.config;
this.config = [config[colIndex]];
config.remove(colIndex);
this.setConfig(config);
}
});
Ext.override(Ext.grid.GridPanel,{
addColumn: function(field, column, colIndex){
if(!column){
if(field.dataIndex){
column = field;
field = field.dataIndex;
} else{
column = field.name || field;
}
}
this.store.addField(field);
this.colModel.addColumn(column, colIndex);
},
removeColumn: function(name, colIndex){
this.store.removeField(name);
if(typeof colIndex != 'number'){
colIndex = this.colModel.findColumnIndex(name);
}
if(colIndex >= 0){
this.colModel.removeColumn(colIndex);
}
}
});
使用方法:
var grid = new Ext.grid.GridPanel({
store: new Ext.data.SimpleStore({
fields: ['A', 'B'],
data: [['ABC', 'DEF'], ['GHI', 'JKL']]
}),
columns: [
{header: 'A', dataIndex: 'A'},
{header: 'B', dataIndex: 'B'}
]
});
new Ext.Viewport({
layout: 'fit',
items: grid
});
grid.addColumn('C');
grid.addColumn({name: 'D', defaultValue: 'D'}, {header: 'D', dataIndex: 'D'});
grid.removeColumn('B');
この記事は、次のように掲載されています.
http://www.17ext.com/showtopic-1759.aspx、コードを直接実行するように割り当てましたよ!
grid.addColumn('C');//C列追加、空データ
grid.addColumn({name: 'D', defaultValue: 'D'}, {header: 'D', dataIndex: 'D'});//D列追加、Dデータあり
grid.removeColumn('B');//前のB列を削除する
再び突き落とす
http://www.17ext.com/