1
A
回答
1
我創建一個dynamicgridpanel
組分:
Ext.define('Ext.ux.grid.DynamicGridpanel', {
extend: 'Ext.grid.Panel',
alias: 'widget.dynamicgridpanel',
/* author: Alexander Berg, Hungary */
storeUrl: '', //some url here
columnDefinitionUrl: '', //some url here
columnDefinitionParams: {}, //params here
columns: [],
capitalize: true,
storeAutoLoad: false,
/* Make a call to the server for the columns definiton, create a store, reconfigure the grid with it */
initComponent: function() {
var me = this;
me.callParent(arguments);
me.addEvents({'afterColumndefinitionsLoad' : true},{'beforeColumndefinitionsLoad' : true});
me.fireEvent('beforeColumndefinitionsLoad', me);
// make an ajax request to get the grids column definiton from server
Ext.Ajax.request({
url: me.columnDefinitionUrl,
params: me.columnDefinitionParams,
success: function (response) {
var object = Ext.decode(response.responseText, false);
//if the response has sent back a List of strings i.e. "columns" : ["dataindex1","dataindex2","dataindex3"]
if (object.columnsNames) {
var columnsFromServer = [];
if(Ext.isArray(object.columnsNames)) {
for (var x in object.columnsNames) {
var columnText = object.columnsNames[x];
if (me.capitalize) {
columnText = Ext.String.capitalize(columnText);
}
columnsFromServer.push({ dataIndex: object.columnsNames[x], text: columnText});
}
} else {
var columnText = object.columnsNames;
if (me.capitalize) {
columnText = Ext.String.capitalize(columnText);
}
columnsFromServer.push({ dataIndex: object.columnsNames, text: columnText});
}
//if the response has sent back a List of column objects i.e. "columns" : [{"dataindex1"},"dataindex2","dataindex3"]
} else if (object.columns) {
var columnsFromServer = object.columns
} else {
Ext.Msg.show({
title:'Error',
msg: 'No columnsNames and no columns!',
buttons: Ext.Msg.OK,
icon: Ext.Msg.ERROR
});
}
var fields = [];
Ext.each(columnsFromServer, function (column) {
fields.push(column.dataIndex);
});
// create the store
var storeConfig = {
storeId: 'store_' + me.id,
fields: fields,
autoLoad: me.storeAutoLoad,
proxy: {
type: 'ajax',
url: me.storeUrl,
reader: {
type: 'json',
root: me.storeRoot,
successProperty: 'success'
}
}
};
if (me.storeParams) {
storeConfig.proxy.extraParams = me.storeParams;
}
var store = Ext.create('Ext.data.Store', storeConfig);
me.reconfigure(store, columnsFromServer); // reconfigure the store, and the columns
me.fireEvent('afterColumndefinitionsLoad', me);
}
});
}
});
用法:
{
xtype : 'dynamicgridpanel',
storeUrl : '/something/data/testData.json',
storeParams : {
param1 : 'param1',
param2 : 'param2'
},
storeRoot : 'storeData',
storeAutoLoad : true,
columnDefinitionUrl : '/something/data/testCol.json',
columnDefinitionParams : {
param1 : 'param1',
param2 : 'param2'
}
}
例如用於/something/data/testCol.json
:
{
msg : "Success",
success : true,
columnsNames : ["column1", "column2", "column3", "column4"]
}
例如用於/something/data/testData.json
:
{
msg : "Success",
success : true,
storeData : [
{column1: "row1 col1", column2: "row1 col2", column3: "row1 col3", column4: "row1 col4"},
{column1: "row2 col1", column2: "row2 col2", column3: "row2 col3", column4: "row2 col4"},
{column1: "row3 col1", column2: "row3 col2", column3: "row3 col3", column4: "row3 col4"}
]
}
相關問題
- 1. 如何檢索動態列?
- 2. 從JSON數據動態檢索列
- 3. 動態檢索xml數據
- 4. 如何從數據庫動態檢索數據
- 5. Struts2 - 動態表單域和數據庫數據檢索
- 6. 如何存儲和檢索動態列表視圖
- 7. 通過json檢索動態數據
- 8. 從動態網站檢索數據
- 9. PHP(7)動態會話數據檢索
- 10. 從動態表格檢索數據
- 11. 在動態控件上檢索數據
- 12. 火力地堡檢索數據動態
- 13. 如何檢索序列化數據?
- 14. 如何檢索特定的列數據
- 15. 如何從Footable中檢索列數據
- 16. 如何從html中動態創建表格中檢索數據
- 17. 如何從數據庫檢索值到動態文本框
- 18. 如何從動態生成的UITextField中檢索數據?
- 19. 如何從數據庫中檢索動態內容?
- 20. 檢索狀態數據
- 21. COBOL如何存儲和檢索數據?
- 22. 如何檢索和處理Gmail數據
- 23. 如何獲得NSManagedObjectId和檢索數據
- 24. 數據檢索和索引
- 25. 用C#創建,存儲和檢索動態數據
- 26. 從LINQ動態sql查詢檢索和打印數據
- 27. 域驅動設計:如何檢索複雜數據列表
- 28. 如何從TextBox中檢索數據,並通過按鈕動態添加數據?
- 29. 實體框架:如何動態檢索列和外鍵列DatabaseGeneratedOptions導航性能?
- 30. 從Redis獲取陣列數據 - 如何存儲和檢索
你是什麼意思你想要動態檢索列模型 –
列。對不起,這是另一回事嗎?那裏。我編輯了我的問題。對於那個很抱歉。 – hermann
我不知道你想要什麼很容易。根據我的理解,您想要獲取數據,然後根據從Web服務返回的數據創建列? –