[转]收藏的Extjs 多表头插件GroupHeaderGrid
效果图:
是不是非常酷啊!
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的更多相关文章
- Extjs 使用fileupload插件上传文件 带进度条显示
一.首先我们看看官方给出的插件的解释: 一个文件上传表单项具有自定义的样式,并且可以控制按钮的文本和 像文本表单的空文本类似的其他特性. 它使用一个隐藏的文件输入元素,并在用户选择文件后 在form提 ...
- 开发extjs常用的插件
Spket是目前支持Ext 2.0最为出色的IDE. 它采用.jsb project file 文件并将继承于基类和所有文档的内容嵌入到生成代码提示的Script doc中.注:不支持配置项的代码提示 ...
- JQuery固定表头插件fixedtableheader源码注释
在开发XX车站信息系统时,需要将大量数据显示在一个巨大的表格内部,由于表格是一个整体,无法分页,加之数据很多,超出一屏,为了方便用户,决定使用固定表头的插件,经过测试,发现JQuery 插件:fixe ...
- SenCha Touch 与 EXTJS 安装Myeclipse 插件
http://www.cnblogs.com/jirimutu01/default.html 关于SenchaEclipsePlugin插件的安装和使用 使用过eclipse开发java程序的人都知道 ...
- ExtJs工具篇(1)——在Aptana3中安装ExtJS 代码提示插件
首先得下载Aptana 这个软件,我下载的是Aptana3这个版本.下载后,在"帮助"菜单中选择"安装新软件",弹出下面的对话框: 我们需要安装一个叫做&quo ...
- ExtJs 继承 和 插件 示例
Ext.ns('Ext.ux'); function btn(){ alert(this.id); }; var panel_plugs = {//定义插件 init : function(panel ...
- 【收藏】下载Chrome商店插件的方法,万恶的gwd
以下是下载离线插件包的方法: 第一步: 每个Google Chrome扩展都有一个固定的ID,例如https://chrome.google.com/webstore/detail/bfbmjmiod ...
- ExtJs如何使用自定义插件动态保存表头配置(隐藏或显示)
关于保存列表表头的配置,一般我们不需要与后台交互,直接保存在 localStorage 中就能满足常规使用需求(需要浏览器支持). 直接上代码,插件: Ext.define('ux.plugin.Co ...
- 使用FlexiGrid实现Extjs表格的效果-网络传输小,更方便!
近一段时间Extjs真的是风光无限好,只要是个做CRM/HRM之类的企业现在都在琢磨怎么在项目中用它,不过兄弟我可是不敢,原因很简单:太大/太笨/源码不好调试.但是对于Extjs漂亮的表格与功能的 ...
随机推荐
- C#代码规范-编程秘笈
原文地址:https://www.cnblogs.com/zzp0320/p/6949973.html 1.引言 本文是一套面向C# programmer和C# developer进行开发所应遵循的开 ...
- Swift 类型检查与类型转换
前言 在 Swift 语言中一般使用 is 关键字实现类型检查,使用 as 关键字实现类型转换,除此之外还可以通过构造器和方法来实现类型转换. 1.类型检查 1.1 使用 is 检查 类型检查操作符 ...
- zookeeper注册中心安装(单机版)
下载zookeeper-3.4.9.tar.gz wget http://apache.fayea.com/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar. ...
- asp.net C#取Excel 合并单元格内容
asp教程.net c#取excel 合并单元格内容读取excel数据,填充dataset// 连接字符串 string xlspath = server.mappath("~/www.11 ...
- excel中对数据进行分类求和
我们在用excel处理数据时,常常需要按不同的类别分别汇总数据.例如下图中需要求出每个业务员的总销售金额等. 通常情况下我们的数据量很大,而且需要较快的统计出来结果,所以我们要用一定的技巧才能计算出来 ...
- [转]八幅漫画理解使用JSON Web Token设计单点登录系统
上次在<JSON Web Token - 在Web应用间安全地传递信息>中我提到了JSON Web Token可以用来设计单点登录系统.我尝试用八幅漫画先让大家理解如何设计正常的用户认证系 ...
- 常用代码之四:创建jason,jason转换为字符串,字符串转换回jason,c#反序列化jason字符串的几个代码片段
1.创建jason,并JSON.stringify()将之转换为字符串. 直接使用var customer={}, 然后直接customer.属性就可以直接赋值了. 也可以var customer = ...
- application配置和profile隔离配置(转)
前言 github: https://github.com/vergilyn/SpringBootDemo 说明:我代码的结构是用profile来区分/激活要加载的配置,从而在一个project中写各 ...
- git概念及工作流程详解
git概念及工作流程详解 既然我们已经把gitlab安装完毕[当然这是非必要条件],我们就可以使用git来管理自己的项目了,前文也多多少少提及到git的基本命令,本文就先简单对比下SVN与git的区别 ...
- unity, ugui toggle, dynamic bool
假设Canvas_debugControl.cs有一个函数 public void showNextSceneButton(bool value){ ... } 欲将其添加到一个ugui toggle ...


