這個(gè)問題糾結(jié)了我很久,本來想找個(gè)插件來解決的,但好像很少拿Extjs做報(bào)表啊,這么常用的功能竟然沒有好的解決辦法,唯一找到的一個(gè)插件就是AutoGrid2,可并不能解決問題,最后在老外的一段代碼下終于找到了解決方法,原來如此簡(jiǎn)單. 數(shù)據(jù)源: 1: {'data':[{'number':'1','text1': '3','info1': '4','special1': '5'},{'number':'1','text1': '3','info1': '4','special1': '5'}], 2: 'columModle':[ 3: {'header': '序號(hào)','dataIndex': 'number','width':40}, 4: {'header': '編碼','dataIndex': 'text1'}, 5: {'header': '名稱','dataIndex': 'info1'}, 6: {'header': '金額','dataIndex': 'special1'} 7: ], 8: 'fieldsNames':[{name: 'number'},{name: 'text1'}, {name: 'info1'},{name: 'special1'}] 9: } js: 1: Ext.onReady(function() { 2: 3: var conn = new Ext.data.Connection(); 4: conn.request({ url: '/Scripts/11.js', callback: function(options, success, response) { 5: var json = new Ext.util.JSON.decode(response.responseText); 6: var cm = new Ext.grid.ColumnModel(json.columModle); 7: var ds = new Ext.data.JsonStore({ 8: data: json.data, 9: fields:json.fieldsNames 10: }); 11: var grid = new Ext.grid.GridPanel({ 12: height: 200, 13: width: 400, 14: region: 'center', 15: split: true, 16: border: false, 17: store: ds, 18: cm: cm 19: }); 20: 21: grid.render('grid-example'); 22: } 23: }); |
|