打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Dynamic Grid(二)
Ext.grid.DynamicColumnModel = function(store) {
var cols = [];
var recordType = store.reader.recordType;
var fields = recordType.prototype.fields;

if ( fields.length == 0 )
{
fields = store.reader.headers;
for ( var i = 0; i < store.reader.headers.length; i++ )
{
var header = store.reader.headers[i]
cols[i] = {
header: header.text,
dataIndex: header.name,
tooltip: '',
hidden: header.hidden,
renderer: function(value,atts){
atts.attr = 'ext:qtip="'+Ext.util.Format.htmlEncode(value) +'"';
return value;
}
};
}
}
else
{
for (var i = 0; i < fields.keys.length; i++) {
var fieldName = fields.keys[i];
var field = recordType.getField(fieldName);
cols[i] = {
header: field.header,
dataIndex: field.name,
tooltip: field.tooltip,
hidden: field.hidden,
sortable:true, //for sorting
renderer: function(value,atts){
atts.attr = 'ext:qtip="'+Ext.util.Format.htmlEncode(value) +'"';
return value;
}
};
}
}
// for sorting
store.fields = store.reader.recordType.prototype.fields;

Ext.grid.DynamicColumnModel.superclass.constructor .call(this, cols);
};
Ext.extend(Ext.grid.DynamicColumnModel, Ext.grid.ColumnModel, {});


Ext.data.DynamicXmlReader = function(config) {
Ext.data.DynamicXmlReader.superclass.constructor.c all(this, config, []);
};
Ext.extend(Ext.data.DynamicXmlReader, Ext.data.XmlReader, {
getRecordType : function(data) {
recordDefinition = Ext.DomQuery.select(this.meta.recordDefinition + ' > *', data);
var arr = [];
for (var i = 0; i < recordDefinition.length; i++) {
arr[i] = {
name: recordDefinition[i].tagName,
header: recordDefinition[i].getAttribute('header'),
tooltip: recordDefinition[i].getAttribute('tooltip'),
hidden: recordDefinition[i].getAttribute('hidden') == "true" ? true : false
};
}

this.recordType = Ext.data.Record.create(arr);
return this.recordType;
},

readRecords : function(doc) {
this.xmlData = doc;
var root = doc.documentElement || doc;
this.getRecordType(root);
return Ext.data.DynamicXmlReader.superclass.readRecords.c all(this, doc);
}
});

Ext.grid.GridView.prototype.bindColumnModel = function(cm) {
if(this.cm){
this.cm.un("widthchange", this.updateColumns, this);
this.cm.un("headerchange", this.updateHeaders, this);
this.cm.un("hiddenchange", this.handleHiddenChange, this);
this.cm.un("columnmoved", this.handleColumnMove, this);
}
if(cm){
cm.on("widthchange", this.updateColumns, this);
cm.on("headerchange", this.updateHeaders, this);
cm.on("hiddenchange", this.handleHiddenChange, this);
cm.on("columnmoved", this.handleColumnMove, this);
}
this.cm = cm;
};

Ext.grid.DynamicGridPanel = function(config) {
this.store = config.store;
this.renderTo = config.renderTo;
this.view = config.view;
this.plugins = config.plugins;
Ext.grid.DynamicGridPanel.superclass.constructor.c all(this, this.renderTo, config);
};
Ext.extend(Ext.grid.DynamicGridPanel, Ext.grid.GridPanel, {
render : function() {
this.store.addListener('load', this.doReconfiguration, this);
this.colModel = new Ext.grid.DefaultColumnModel([{ header: '', dataIndex: '' }]);
Ext.grid.DynamicGridPanel.superclass.render.call(t his);
},

doReconfiguration : function() {
this.colModel = new Ext.grid.DynamicColumnModel(this.store);
this.view.bindColumnModel(this.colModel);
this.view.refresh(true);
this.store.removeListener("load", this.doReconfiguration);
}
});


And here is an example:


viewgrid = new Ext.grid.DynamicGridPanel({
renderTo: 'view-south-grid',
store: viewds,
enableColumnMove: true,
sortable: true,
autoheight:true,
bodyBorder : false,
monitorWindowResize : true,
autoScroll: true,
listeners: {
destroy: function(c) {
c.getStore().destroy();
}
},
viewConfig: {
forceFit: true
},
view: new Ext.grid.GroupingView({
autofill : true,
forceFit: true,
startCollapsed : true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
})
});
viewgrid.render();
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Ext.grid.ColumnModel
Extjs 下拉grid
EXT 列头合并的例子 - Winner.Net@2007 - 博客园
ExtJS的使用方法汇总—配置和表格控件使用
验证
grid中某一列显示图片链接,触发单击事件,弹出本页的另一个form
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服