ExtJs 實現動態列,動態多表頭

來源:互聯網
上載者:User

先看看效果 

效果不錯吧,就是樣式稍微差點,沒辦法Extjs的表頭是漸層的,不過樣式改起來應該不難.

接下來是資料:

   1:  "{columModle:[{header:\"用電單位\",dataIndex:\"用電單位\"},
   2:  {header:\"2009-06   _度數\",dataIndex:\"2009-06   _度數\"},
   3:  {header:\"2009-06   _單價\",dataIndex:\"2009-06   _單價\"},
   4:  {header:\"2009-06   _金額\",dataIndex:\"2009-06   _金額\"},
   5:  {header:\"2009-07   _度數\",dataIndex:\"2009-07   _度數\"},
   6:  {header:\"2009-07   _單價\",dataIndex:\"2009-07   _單價\"},
   7:  {header:\"2009-07   _金額\",dataIndex:\"2009-07   _金額\"},
   8:  {header:\"2009-08   _度數\",dataIndex:\"2009-08   _度數\"},
   9:  {header:\"2009-08   _單價\",dataIndex:\"2009-08   _單價\"},
  10:  {header:\"2009-08   _金額\",dataIndex:\"2009-08   _金額\"},
  11:  {header:\"合計_度數\",dataIndex:\"合計_度數\"},
  12:  {header:\"合計_金額\",dataIndex:\"合計_金額\"}],
  13:  fieldsNames:[{name:\"用電單位\"},{name:\"2009-06   _度數\"},{name:\"2009-06   _單價\"},{name:\"2009-06   _金額\"},{name:\"2009-07   _度數\"},
  14:  {name:\"2009-07   _單價\"},{name:\"2009-07   _金額\"},{name:\"2009-08   _度數\"},{name:\"2009-08   _單價\"},{name:\"2009-08   _金額\"},
  15:  {name:\"合計_度數\"},{name:\"合計_金額\"}],
  16:  data:[{\"用電單位\":\"1\",\"2009-06   _度數\":\"\",\"2009-06   _單價\":\"\",\"2009-06   _金額\":\"\",\"2009-07   _度數\":\"1.00\",\"2009-07   _單價\":\"2.00\",\"2009-07   _金額\":\"2.0000\",\"2009-08   _度數\":\"4.00\",\"2009-08   _單價\":\"2.00\",\"2009-08   _金額\":\"8.0000\",\"合計_度數\":\"5.00\",\"合計_金額\":\"10.0000\"}]}"

主要是紅色的部分

然後是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) {
  10:                  if (item >= 0) {
  11:                      var tempHeader = json.columModle[item].header
  12:                      if (tempHeader.split('_').length > 1) {
  13:                          _temp.push(tempHeader.split('_')[0]);
  14:                          json.columModle[item].header = tempHeader.split('_')[1];
  15:                      }
  16:                      else
  17:                          _temp.push("");
  18:                  }
  19:              }
  20:              var i = 1;
  21:              for (var item in _temp) {
  22:                  if (item >= 0) {
  23:                      if (_temp[item] != _temp[Number(item) + 1]) {
  24:                          jsonrows += "{header:'" + _temp[item] + "',colspan:" + i + ",align:'center'},";
  25:                          i = 1;
  26:                      }
  27:                      else {
  28:                          i++;
  29:                      }
  30:                  }
  31:              }
  32:              jsonrows = jsonrows.substring(0, jsonrows.length - 1);
  33:              jsonrows += "]]";
  34:              var cm = new Ext.grid.ColumnModel({ columns: json.columModle,
  35:                  rows: new Ext.util.JSON.decode(jsonrows)
  36:              });
  37:              var ds = new Ext.data.JsonStore({
  38:                  data: json.data,
  39:                  fields: json.fieldsNames
  40:              });
  41:              var grid = new Ext.grid.EditorGridPanel({
  42:                  height: 400,
  43:                  region: 'center',
  44:                  split: true,
  45:                  border: false,
  46:                  store: ds,
  47:                  plugins: [new Ext.ux.plugins.GroupHeaderGrid()],
  48:                  cm: cm
  49:              });
  50:              grid.render('grid-example');
  51:          }
  52:          });
  53:      });

實現多表頭的方法依然是我上篇文章的方法http://www.cnblogs.com/doublog/archive/2009/07/09/1519538.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.