[转]收藏的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漂亮的表格与功能的 ...
随机推荐
- php执行多个存储过程
2014年3月18日更新: 从以前的使用原生代码来看,只需要将结果集关闭即可,即 $this -> queryID -> close(); . // 使用mysqli方式,修改DbMysq ...
- 编码 GBK 的不可映射字符
一般做项目公司都会统一要求文件编码类型,很多为了实现应用国际化和本地化和更高的性能,而选用UTF-8而非GBK. 但在开发过程中我们都用的是IDE,只要更改了配置就不用操心了,但有时我们也会用命令行来 ...
- Innodb的内存结构
1.缓冲池从1.0.x版本开始,允许有多个缓冲池实例. mysql> show variables like 'innodb_buffer_pool_size'\G ************** ...
- 从语句 char* p="test" 说起
我相信,使用C/C++多年的人对下面这个字符串赋值语句都不会陌生吧. char* p = "test"; 同时,我也相信,各位在使用这种语句后吃 ...
- selenium webdriver如何拿到页面的加载时间
这个问题与语言无关,对于现代浏览器来说,使用 window.performance.timing这个对象就好了. 用execute_script方法(java用executeScript)方法执行 w ...
- winform中键盘和鼠标事件的捕捉和重写
在编写winform应用程序时,有时需要无论在哪个控件获取焦点时,对某一个键盘输入或者鼠标事件都进行同样的操作.比如编写一个处理图片的应用程序时,希望无论当前哪个控件获得焦点,当用户按上.下.左.右键 ...
- application配置和profile隔离配置(转)
前言 github: https://github.com/vergilyn/SpringBootDemo 说明:我代码的结构是用profile来区分/激活要加载的配置,从而在一个project中写各 ...
- Java数据结构和算法(六):前缀、中缀、后缀表达式
前面我们介绍了三种数据结构,第一种数组主要用作数据存储,但是后面的两种栈和队列我们说主要作为程序功能实现的辅助工具,其中在介绍栈时我们知道栈可以用来做单词逆序,匹配关键字符等等,那它还有别的什么功能吗 ...
- vue-router路由的使用
1.路由作用 用vue.js + vue-router创建单页面应用.页面不需要刷新就可以页面跳转,提供用户更好体验. 2.路由配置 new Router({ routes: [{ path: '/' ...
- 香蕉派 banana pi BPI-M3 八核开源硬件开发板
Banana PI BPI-M3 是一款8核高性能单板计算机,Banana PI BPI-M3是一款比树莓派 2 B更强悍的8核Android 5.1产品. Banana PI BPI-M3 兼 ...


