First look at the effect
The effect is good, is the style is slightly almost, no way to ExtJS the head of the table is a gradient, but the style should not be difficult to change.
Next is the data:
1: "{colummodle:[{header:\", dataindex:\ "Electricity Unit \"},
2: {header:\ "2009-06 _ Degrees", dataindex:\ "2009-06 _ Degrees \"},
3: {header:\ "2009-06 _ Unit price \", dataindex:\ "2009-06 _ Unit price \"},
4: {header:\ "2009-06 _ Amount \", dataindex:\ "2009-06 _ Amount \"},
5: {header:\ "2009-07 _ Degrees", dataindex:\ "2009-07 _ Degrees \"},
6: {header:\ "2009-07 _ Unit price \", dataindex:\ "2009-07 _ Unit price \"},
7: {header:\ "2009-07 _ Amount \", dataindex:\ "2009-07 _ Amount \"},
8: {header:\ "2009-08 _ Degrees", dataindex:\ "2009-08 _ Degrees \"},
9: {header:\ "2009-08 _ Unit price \", dataindex:\ "2009-08 _ Unit price \"},
{header:\ "2009-08 _ Amount \", dataindex:\ "2009-08 _ Amount \"},
One: {header:\ "total _ degrees \", dataindex:\ "total _ degrees \"},
{header:\ "total _ Amount \", dataindex:\ "total _ Amount \"}],
fieldsnames:[{name:\ "power unit \"},{name:\ "2009-06 _ Degrees"},{name:\ "2009-06 _ Unit price \"},{name:\ "2009-06 _ Amount \ "},{name:\" 2009-07 _ Degrees \ "},
: {name:\ "2009-07 _ Unit price \"},{name:\ "2009-07 _ Amount \"},{name:\ "2009-08 _ degrees \"},{name:\ "2009-08 _ Unit price \ "},{name:\" 2009-08 _ Amount \ "},
{name:\ "total _ degree \"},{name:\ "Total _ Amount \"}],
: data:[{\ "power unit \": \ "1\", "2009-06 _ degrees": \ "\", \ "2009-06 _ Unit price \": \ "\", "2009-06 _ amount \": \ "", \ " 2009-07 _ degree \ ": \" 1.00\ "," 2009-07 _ Unit price \ ": \" 2.00\ ", \" 2009-07 _ Amount ":" 2.0000\ "," 2009-08 _ Degrees ":" 4.00\ ", \" 2009-08 _ Unit price \ ": \" 2.00\ ", \" 2009-08 _ amount \ ": \" 8.0000\ ", \" Total _ degrees ": \" 5.00\ ", \" Total _ amount \ ": \" 10.0000\ "}] }"
Mostly red parts.
Then the JS:
1: Ext.onready (function () {
2: var conn = new Ext.data.Connection ();
3: conn.request ({url: '/power/powerstatlist ', callback:function (options, success, response) {
4: var a = Response.responsetext;
5: var json = new Ext.util.JSON.decode (eval (a));
6: var jsonrows = "[[];"
7: var rows = {};
8: var _temp = [];
9: For (var item in Json.colummodle) {
if (item >= 0) {
One: var tempheader = Json.colummodle[item].header
if (tempheader.split ('_'). length > 1) {
_temp.push (Tempheader.split ('_') [0]);
: json.colummodle[item].header = Tempheader.split ('_') [1];
: }
/ Else
: _temp.push ("");
: }
: }
: var i = 1;
: For (var item in _temp) {
: if (item >= 0) {
: if (_temp[item]!= _temp[number (item) + 1]) {
Jsonrows + = "{header: '" + _temp[item] + "', colspan:" + i + ", align: ' center '},";
: i = 1;
: }
/ Else {
: i++;
: }
: }
: }
jsonrows = jsonrows.substring (0, jsonrows.length-1);
: jsonrows + = "]";
$: var cm = new Ext.grid.ColumnModel ({columns:json.columModle,
rows:new Ext.util.JSON.decode (jsonrows)
: });
Notoginseng: var ds = new Ext.data.JsonStore ({
Data:json.data,
Fields:json.fieldsNames:
: });
$: var Grid = new Ext.grid.EditorGridPanel ({
: height:400,
region: ' Center ',
: Split:true,
A: Border:false,
Store:ds,
plugins: [New Ext.ux.plugins.GroupHeaderGrid ()],
CM:CM:
: });
: grid.render (' grid-example ');
Wuyi: }
: });
: });
The way to implement multiple headers is still the method of my last article http://www.cnblogs.com/doublog/archive/2009/07/09/1519538.html