效果图:

是不是非常酷啊!


js 代码:

Ext.namespace("Ext.tet.plugins");

Ext.tet.plugins.GroupHeaderGrid = function(config) {
 Ext.apply(this, config);
};

Ext.extend(Ext.tet.plugins.GroupHeaderGrid, Ext.util.Observable, {
 init: function(grid) {
  var v = grid.getView();
  v.beforeMethod('initTemplates', this.initTemplates);
  v.renderHeaders = this.renderHeaders.createDelegate(v, [v.renderHeaders]);
        v.afterMethod('onColumnWidthUpdated', this.updateGroupStyles);
        v.afterMethod('onAllColumnWidthsUpdated', this.updateGroupStyles);
  v.afterMethod('onColumnHiddenUpdated', this.updateGroupStyles);
  v.getHeaderCell = this.getHeaderCell;
  v.updateSortIcon = this.updateSortIcon;
  v.getGroupStyle = this.getGroupStyle;
 },

 initTemplates: function() {
  var ts = this.templates || {};
  if (!ts.gheader) {
   ts.gheader = new Ext.Template(
    '<table border="0" cellspacing="0" cellpadding="0" class="ux-grid-group-table" style="{tstyle}">',
    '<thead>{rows}{header}</thead>',
    '</table>'
   );
  }
  if (!ts.header) {
   ts.header = new Ext.Template(
    '<tr class="x-grid3-hd-row">{cells}</tr>'
   );
  }
  if (!ts.gcell) {
   ts.gcell = new Ext.Template(
    '<td class="x-grid3-hd {cls} x-grid3-td-{id}" style="{style}" rowspan="{rowspan}" colspan="{colspan}">',
    '<div {tooltip} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">{value}</div>',
    '</td>'
   );
  }
  this.templates = ts;
 },

 renderHeaders: function(renderHeaders) {
  var ts = this.templates, rows = [], table = [];
  for (var i = 0; i < this.cm.rows.length; i++) {
   var r = this.cm.rows[i], cells = [], col = 0;
   for (var j = 0; j < r.length; j++) {
    var c = r[j];
    c.colspan = c.colspan || 1;
    c.rowspan = c.rowspan || 1;
    while (table[i] && table[i][col]) {
     col++;
    }
    c.col = col;
    for (var rs = i; rs < i + c.rowspan; rs++) {
     if (!table[rs]) {
      table[rs] = [];
     }
     for (var cs = col; cs < col + c.colspan; cs++) {
      table[rs][cs] = true;
     }
    }
    var gs = this.getGroupStyle(c);
    cells[j] = ts.gcell.apply({
     id: c.id || i + '-' + col,
     cls: c.header ? 'ux-grid-hd-group-cell' : 'ux-grid-hd-nogroup-cell',
     style: 'width:' + gs.width + ';' + (gs.hidden ? 'display:none;' : '') + (c.align ? 'text-align:' + c.align + ';' : ''),
     rowspan: c.rowspan,
     colspan: gs.colspan,
     tooltip: c.tooltip ? (Ext.QuickTips.isEnabled() ? 'ext:qtip' : 'title') + '="' + c.tooltip + '"' : '',
     value: c.header || ' ',
     istyle: c.align == 'right' ? 'padding-right:16px' : ''
    });
   }
   rows[i] = ts.header.apply({
    cells: cells.join('')
   });
  }
  return ts.gheader.apply({
   tstyle: 'width:' + this.getTotalWidth() + ';',
   rows: rows.join(''),
   header: renderHeaders.call(this)
  });
 },

 getGroupStyle: function(c) {
  var w = 0, h = true, cs = 0;
  for (var i = c.col; i < c.col + c.colspan; i++) {
   if (!this.cm.isHidden(i)) {
    var cw = this.cm.getColumnWidth(i);
    if(typeof cw == 'number'){
     w += cw;
    }
    h = false;
    cs++;
   }
  }
  return {
   width: (Ext.isBorderBox ? w : Math.max(w - this.borderWidth, 0)) + 'px',
   hidden: h,
   colspan: cs || 1
  }
 },

 updateGroupStyles: function(col) {
  var rows = this.mainHd.query('tr.x-grid3-hd-row');
  for (var i = 0; i < rows.length - 1; i++) {
   var cells = rows[i].childNodes;
   for (var j = 0; j < cells.length; j++) {
    var c = this.cm.rows[i][j];
    if ((typeof col != 'number') || (col >= c.col && col < c.col + c.colspan)) {
     var gs = this.getGroupStyle(c);
     cells[j].style.width = gs.width;
     cells[j].style.display = gs.hidden ? 'none' : '';
     cells[j].colSpan = gs.colspan;
    }
   }
  }
 },

 getHeaderCell : function(index){
  return this.mainHd.query('td.x-grid3-cell')[index];
 },

 updateSortIcon : function(col, dir){
  var sc = this.sortClasses;
  var hds = this.mainHd.select('td.x-grid3-cell').removeClass(sc);
  hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
 }
});
css 代码:

.x-grid3-header-offset {
 width: auto;
}
.ext-ie .x-grid3 table.ux-grid-group-table, .ext-safari .x-grid3 table.ux-grid-group-table {
 table-layout: auto;
}
.ux-grid-hd-group-cell {
 background: url(../../../client/ext/resources/images/default/grid/grid3-hrow.gif) repeat-x bottom;
}


调用方式:(主要是 ColumnModel 的 rows 属性不同)

var cm = new Ext.grid.ColumnModel({ 
                 columns:[
                  new Ext.grid.CheckboxSelectionModel({handleMouseDown:Ext.emptyFn}),
                 {
                  header:"序号",
                  dataIndex:"ID",
                        sortable:true
                 },{
                  header:"借书单号",
                  dataIndex:"BorrowNo",
                        searchable:true,
                        attribute:{type:"string",dateFormat:""},       
                        sortable:true
                 },{
                  header:"借书人",
                  tooltip:"借书人",
                  dataIndex:"LoginName",
                        searchable:true,
                        attribute:{type:"string",dateFormat:""},   
                        sortable:true
                 },{
                  header:"身份证",
                  dataIndex:"IdentityCard",
                     searchable:false,
                     attribute:{type:"string",dateFormat:""},   
                        sortable:true
                 },{
                  header:"图书代码",
                  dataIndex:"BCode",
                  attribute:{type:"string",dateFormat:""},  
                        sortable:true
                 },{
                  header:"图书名称",
                  tooltip:"图书名称",
                  dataIndex:"BName",
                        sortable:true
                 },{
                  header:"借书时间",
                  dataIndex:"BorrowDate",
                  searchable:true,
                  attribute:{type:"date",dateFormat:'Y-m-d'}, 
                  renderer: Ext.util.Format.dateRenderer('Y-m-d'), 
                        sortable:true
                 },{
                  header:"借书数量",
                  dataIndex:"BookNum",
                  searchable:true,
                  attribute:{type:"int"},   
                        sortable:true
                 },{
                  header:"费用",
                  dataIndex:"Charge",
                  searchable:true,
                  attribute:{type:"float"},   
                        sortable:true
                 }],
                 defaultSortable: true,
        rows: [
             [
              {rowspan: 2},
              {rowspan: 2},
              {header: 'Before', colspan: 3, align: 'center'},
              {header: 'After', colspan: 2, align: 'center'},
              {header: 'Sum', colspan: 3, align: 'center'}
             ],[
                 {},{},{},{},{},{},{},{} /*******后8列**********/
             ]
        ]
});

var cm = new Ext.grid.ColumnModel({ 
                 columns:[
                  new Ext.grid.CheckboxSelectionModel({handleMouseDown:Ext.emptyFn}),
                 {
                  header:"序号",
                  dataIndex:"ID",
                        sortable:true
                 },{
                  header:"借书单号",
                  dataIndex:"BorrowNo",
                        searchable:true,
                        attribute:{type:"string",dateFormat:""},       
                        sortable:true
                 },{
                  header:"借书人",
                  tooltip:"借书人",
                  dataIndex:"LoginName",
                        searchable:true,
                        attribute:{type:"string",dateFormat:""},   
                        sortable:true
                 },{
                  header:"身份证",
                  dataIndex:"IdentityCard",
                     searchable:false,
                     attribute:{type:"string",dateFormat:""},   
                        sortable:true
                 },{
                  header:"图书代码",
                  dataIndex:"BCode",
                  attribute:{type:"string",dateFormat:""},  
                        sortable:true
                 },{
                  header:"图书名称",
                  tooltip:"图书名称",
                  dataIndex:"BName",
                        sortable:true
                 },{
                  header:"借书时间",
                  dataIndex:"BorrowDate",
                  searchable:true,
                  attribute:{type:"date",dateFormat:'Y-m-d'}, 
                  renderer: Ext.util.Format.dateRenderer('Y-m-d'), 
                        sortable:true
                 },{
                  header:"借书数量",
                  dataIndex:"BookNum",
                  searchable:true,
                  attribute:{type:"int"},   
                        sortable:true
                 },{
                  header:"费用",
                  dataIndex:"Charge",
                  searchable:true,
                  attribute:{type:"float"},   
                        sortable:true
                 }],
                 defaultSortable: true,
        rows: [
             [
              {rowspan: 1},
              {rowspan: 1},
              {header: 'Before', colspan: 3, align: 'center',rowspan: 2},
              {header: 'After', colspan: 2, align: 'center',rowspan: 2},
              {header: 'Sum', colspan: 3, align: 'center',rowspan: 2}
             ],[
                 {},{}  /*******前两列********/
             ]                  
             
        ]
});

var cm = new Ext.grid.ColumnModel({ 
                 columns:[
                  new Ext.grid.CheckboxSelectionModel({handleMouseDown:Ext.emptyFn}),
                 {
                  header:"序号",
                  dataIndex:"ID",
                        sortable:true
                 },{
                  header:"借书单号",
                  dataIndex:"BorrowNo",
                        searchable:true,
                        attribute:{type:"string",dateFormat:""},       
                        sortable:true
                 },{
                  header:"借书人",
                  tooltip:"借书人",
                  dataIndex:"LoginName",
                        searchable:true,
                        attribute:{type:"string",dateFormat:""},   
                        sortable:true
                 },{
                  header:"身份证",
                  dataIndex:"IdentityCard",
                     searchable:false,
                     attribute:{type:"string",dateFormat:""},   
                        sortable:true
                 },{
                  header:"图书代码",
                  dataIndex:"BCode",
                  attribute:{type:"string",dateFormat:""},  
                        sortable:true
                 },{
                  header:"图书名称",
                  tooltip:"图书名称",
                  dataIndex:"BName",
                        sortable:true
                 },{
                  header:"借书时间",
                  dataIndex:"BorrowDate",
                  searchable:true,
                  attribute:{type:"date",dateFormat:'Y-m-d'}, 
                  renderer: Ext.util.Format.dateRenderer('Y-m-d'), 
                        sortable:true
                 },{
                  header:"借书数量",
                  dataIndex:"BookNum",
                  searchable:true,
                  attribute:{type:"int"},   
                        sortable:true
                 },{
                  header:"费用",
                  dataIndex:"Charge",
                  searchable:true,
                  attribute:{type:"float"},   
                        sortable:true
                 }],
                 defaultSortable: true,
        rows: [
             [
              {rowspan: 2},
              {rowspan: 2},
              {header: 'Before', colspan: 3, align: 'center'},
              {header: 'After', colspan: 2, align: 'center',rowspan: 2},
              {header: 'Sum', colspan: 3, align: 'center'}
             ],[
                 /********************Before(共3列)********************/
                 {},
                 {header: 'Before', colspan: 2, align: 'center'},               
                 /********************Sum(共3列)********************/
                 {header: 'Sum', colspan: 2, align: 'center'},
                 {}                
             ]                  
             
        ]
});

[转]收藏的Extjs 多表头插件GroupHeaderGrid的更多相关文章

  1. Extjs 使用fileupload插件上传文件 带进度条显示

    一.首先我们看看官方给出的插件的解释: 一个文件上传表单项具有自定义的样式,并且可以控制按钮的文本和 像文本表单的空文本类似的其他特性. 它使用一个隐藏的文件输入元素,并在用户选择文件后 在form提 ...

  2. 开发extjs常用的插件

    Spket是目前支持Ext 2.0最为出色的IDE. 它采用.jsb project file 文件并将继承于基类和所有文档的内容嵌入到生成代码提示的Script doc中.注:不支持配置项的代码提示 ...

  3. JQuery固定表头插件fixedtableheader源码注释

    在开发XX车站信息系统时,需要将大量数据显示在一个巨大的表格内部,由于表格是一个整体,无法分页,加之数据很多,超出一屏,为了方便用户,决定使用固定表头的插件,经过测试,发现JQuery 插件:fixe ...

  4. SenCha Touch 与 EXTJS 安装Myeclipse 插件

    http://www.cnblogs.com/jirimutu01/default.html 关于SenchaEclipsePlugin插件的安装和使用 使用过eclipse开发java程序的人都知道 ...

  5. ExtJs工具篇(1)——在Aptana3中安装ExtJS 代码提示插件

    首先得下载Aptana 这个软件,我下载的是Aptana3这个版本.下载后,在"帮助"菜单中选择"安装新软件",弹出下面的对话框: 我们需要安装一个叫做&quo ...

  6. ExtJs 继承 和 插件 示例

    Ext.ns('Ext.ux'); function btn(){ alert(this.id); }; var panel_plugs = {//定义插件 init : function(panel ...

  7. 【收藏】下载Chrome商店插件的方法,万恶的gwd

    以下是下载离线插件包的方法: 第一步: 每个Google Chrome扩展都有一个固定的ID,例如https://chrome.google.com/webstore/detail/bfbmjmiod ...

  8. ExtJs如何使用自定义插件动态保存表头配置(隐藏或显示)

    关于保存列表表头的配置,一般我们不需要与后台交互,直接保存在 localStorage 中就能满足常规使用需求(需要浏览器支持). 直接上代码,插件: Ext.define('ux.plugin.Co ...

  9. 使用FlexiGrid实现Extjs表格的效果-网络传输小,更方便!

      近一段时间Extjs真的是风光无限好,只要是个做CRM/HRM之类的企业现在都在琢磨怎么在项目中用它,不过兄弟我可是不敢,原因很简单:太大/太笨/源码不好调试.但是对于Extjs漂亮的表格与功能的 ...

随机推荐

  1. 第2章 Python基础-字符编码&数据类型 字符编码&字符串 练习题

    1.简述位.字节的关系 位(bit)是计算机中最小的表示单元,数据传输是以“位”为单位的,1bit缩写为1b 字节(Byte)是计算机中最小的存储单位,1Byte缩写为1B 8bit = 1Byte ...

  2. 步进电机驱动器 和H桥

    http://bbs.eeworld.com.cn/thread-489952-1-1.html

  3. uiautomatorviewer 查看元素新思路

    用adb 命令把图片和uix获取出来,再导入uiautomatorviewer adb shell uiautomator dump /data/local/tmp/uidump.uixadb pul ...

  4. 请通过vim练习:vim vimtutor

    vim vimtutor ================================================================================ W e l ...

  5. idea没有代码自动提示功能和包自动引入不了问题

    idea没有代码自动提示功能和包自动引入不了问题 原因:节电模式 File -> Power Save Mode (被勾选了) 处理方法: File -> Power Save Mode ...

  6. Eclipse_Configure

    原文链接:http://android.eoe.cn/topic/android_sdk 1. 下载Eclipse 在前面我们配置好了JDK环境后,就可以开始配置Android的集成开发环境了,官方G ...

  7. POJ 3216 Repairing Company(最小路径覆盖)

    POJ 3216 Repairing Company id=3216">题目链接 题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间 ...

  8. Android App开发技能图谱(转载)

    操作系统 Windows/MacOSX/Linux 编程语言 Java HTML/JS (Hybrid/Web App) C/C++ (NDK) SQL (DB) Kotlin 开发工具 IDE An ...

  9. Atitit jquery  1.4--v1.11  v1.12  v2.0  3.0 的新特性

    Atitit jquery  1.4--v1.11  v1.12  v2.0  3.0 的新特性 1.1. Jquery1.12  jQuery 2.2 和 1.12 新版本发布 - OPEN资讯.h ...

  10. Socket网络编程--Libev库学习(3)

    这一小节继续讲解各个观察器(Watcher). 上一小节已经讲解了ev_io(IO可读可写观察器),ev_stat(文件属性变化观察器),ev_signal(信号处理观察器),ev_timer(定时器 ...