/*
* *合并单元格的函数,合并表格内所有连续的具有相同值的单元格。调用方法示例:
* *store.on("load",function(){gridSpan(grid,"row","[FbillNumber],[FbillDate],[FAudit],[FAuditDate],[FSure],[FSureDate]","FbillNumber");});
* *参数:grid-需要合并的表格,rowOrCol-合并行还是列,cols-需要合并的列(行合并的时候有效),sepCols以哪个列为分割(即此字段不合并的2行,其他字段也不许合并),默认为空
*/
function gridSpan(grid, rowOrCol, cols, sepCol){
// alert('grid===='+grid+';rowOrCol='+rowOrCol+';cols='+cols);
var array1 = new Array();
var arraySep = new Array();
var count1 = 0;
var count2 = 0;
var index1 = 0;
var index2 = 0;
var aRow = undefined;
var preValue = undefined;
var firstSameCell = 0;
var allRecs = grid.getStore().getRange();
if(rowOrCol == "row"){
count1 = grid.getColumnModel().getColumnCount(); //列数
count2 = grid.getStore().getCount(); //行数(纪录数)
} else {
count1 = grid.getStore().getCount();
count2 = grid.getColumnModel().getColumnCount();
}
for(i = 0; i < count1; i++){
if(rowOrCol == "row"){
var curColName = grid.getColumnModel().getDataIndex(i); //列名
var curCol = "[" + curColName + "]";
if(cols.indexOf(curCol) < 0)
continue;
} preValue = undefined;
firstSameCell = 0;
array1[i] = new Array();
for(j = 0; j < count2; j++){ if(rowOrCol == "row"){
index1 = j;
index2 = i;
} else {
index1 = i;
index2 = j;
}
var colName = grid.getColumnModel().getDataIndex(index2);
if(sepCol && colName == sepCol)
arraySep[index1] = allRecs[index1].get(sepCol);
var seqOldValue = seqCurValue = "1";
if(sepCol && index1 > 0){
seqOldValue = arraySep[index1 - 1];
seqCurValue = arraySep[index1];
} if(allRecs[index1].get(colName) == preValue && (colName == sepCol || seqOldValue == seqCurValue)){
//alert(colName + "======" + seqOldValue + "======" + seqCurValue);
allRecs[index1].set(colName, "");
array1[i].push(j);
if(j == count2 - 1){
var index = firstSameCell + Math.round((j + 1 - firstSameCell) / 2 - 1);
if(rowOrCol == "row"){
allRecs[index].set(colName, preValue);
} else {
allRecs[index1].set(grid.getColumnModel().getColumnId(index), preValue);
}
}
} else {
if(j != 0){
var index = firstSameCell + Math.round((j + 1 - firstSameCell) / 2 - 1);
if(rowOrCol == "row"){
allRecs[index].set(colName, preValue);
} else {
allRecs[index1].set(grid.getColumnModel().getColumnId(index), preValue);
}
}
firstSameCell = j;
preValue = allRecs[index1].get(colName);
allRecs[index1].set(colName, "");
if(j == count2 - 1){
allRecs[index1].set(colName, preValue);
}
} }
}
grid.getStore().commitChanges(); // 添加所有分隔线
var rCount = grid.getStore().getCount();
for(i = 0; i < rCount; i ++){
hRow = grid.getView().getRows()[i];
hRow.style.border = "none";
//hRow.style.borderBottom= "none";
for(j = 0; j < grid.getColumnModel().getColumnCount(); j ++){
aRow = grid.getView().getCell(i,j);
aRow.style.margin="0";
aRow.style.padding="0"; if(i == 0){
aRow.style.borderTop = "none";
aRow.style.borderLeft = "1px solid #8db2e3"; }else if(i == rCount - 1){
aRow.style.borderTop = "1px solid #8db2e3";
aRow.style.borderLeft = "1px solid #8db2e3";
aRow.style.borderBottom = "1px solid #8db2e3";
}else{
aRow.style.borderTop = "1px solid #8db2e3";
aRow.style.borderLeft = "1px solid #8db2e3";
}
if(j == grid.getColumnModel().getColumnCount()-1)
aRow.style.borderRight = "1px solid #8db2e3";
if(i == rCount-1)
aRow.style.borderBottom = "1px solid #8db2e3";
}
}
// 去除合并的单元格的分隔线
for(i = 0; i < array1.length; i++){
if(!Ext.isEmpty(array1[i])){
for(j = 0; j < array1[i].length; j++){
if(rowOrCol == "row"){
aRow = grid.getView().getCell(array1[i][j],i);
aRow.style.borderTop = "none"; } else {
aRow = grid.getView().getCell(i, array1[i][j]);
aRow.style.borderLeft = "none";
}
}
}
} for(i = 0; i < count1; i++){
if(rowOrCol == "row"){
var curColName = grid.getColumnModel().getDataIndex(i); //列名
var curCol = "[" + curColName + "]";
if(cols.indexOf(curCol) < 0)
continue;
} for(j = 0; j < count2; j++){
var hbcell = grid.getView().getCell(j,i);
hbcell.style.background="#FFF"; //改变合并列所有单元格背景为白色
}
} };

使用方法示例:

 this.gridPanel = new HT.GridPanel({
region : 'center',
tbar : this.topbar,
border:true,
// hideBorders:true,
columnLines:false,
// bodyBorder :false,
// 使用RowActions
rowActions : true,
id : 'PageGrid',
url : __ctxPath + "/qywz/listPage.do",
fields : [ {
name : 'id',
type : 'int'
}, 'name', 'contant', 'edituserid', 'editdate', 'createdate',
'isenabled', 'navigationMenuId' ],
columns : [ {
header : 'id',
dataIndex : 'id',
hidden : true
}, {
header : '页面名称',
dataIndex : 'name'
}, {
header : '内容',
dataIndex : 'contant'
}, {
header : '编辑人',
dataIndex : 'edituserid'
}, {
header : '编辑日期',
dataIndex : 'editdate'
}, {
header : '生成日期',
dataIndex : 'createdate'
}, {
header : '有效标志',
dataIndex : 'isenabled'
}, {
header : '对应导航菜单表ID',
dataIndex : 'navigationMenuId'
}, new Ext.ux.grid.RowActions({
header : '管理',
width : 100,
actions : [ {
iconCls : 'btn-del',
qtip : '删除',
style : 'margin:0 3px 0 3px'
}, {
iconCls : 'btn-edit',
qtip : '编辑',
style : 'margin:0 3px 0 3px'
} ],
listeners : {
scope : this,
'action' : this.onRowAction
}
}) ]
// end of columns
});
var gridp = this.gridPanel; this.gridPanel.addListener('rowdblclick', this.rowClick); // ==>监听load , 执行合并单元格
this.gridPanel.getStore().on('load', function () {
gridSpan(gridp,"row","[name],[contant]"); });

Extjs gridpanel 合并单元格的更多相关文章

  1. extjs grid合并单元格

    http://blog.csdn.net/kunoy/article/details/7829395 /** * Kunoy * 合并单元格 * @param {} grid 要合并单元格的grid对 ...

  2. C# 获取Excel中的合并单元格

    C# 获取Excel中的合并单元格 我们在制作表格时,有时经常需要合并及取消合并一些单元格.在取消合并单元格时需要逐个查找及取消,比较麻烦.这里分享一个简单的方法来识别Excel中的合并单元格,识别这 ...

  3. jquery操作表格 合并单元格

    jquery操作table,合并单元格,合并相同的行 合并的方法 $("#tableid").mergeCell({ cols:[X,X] ///参数为要合并的列}) /** * ...

  4. NPOI操作EXCEL(五)——含合并单元格复杂表头的EXCEL解析

    我们在第三篇文章中谈到了那些非常反人类的excel模板,博主为了养家糊口,也玩命做出了相应的解析方法... 我们先来看看第一类复杂表头: ...... 博主称这类excel模板为略复杂表头模板(蓝色部 ...

  5. poi获取合并单元格内的第一行第一列的值

    当读取如图所示的excel时,显示为第1行 第1列 的内容是:合并单元格 其它在合并单元格区域内的单元格不显示 示例代码如下: import java.io.FileInputStream; impo ...

  6. Repeater多列分别合并单元格

    GridView.Repeater合并单元格可以参考http://www.cnblogs.com/zhmore/archive/2009/04/22/1440979.html,但是原文例子是合并一列的 ...

  7. Aspose.Cells 首次使用,用到模版填充数据,合并单元格,换行

    Aspose.Cells 首次使用,用到模版填充数据,合并单元格,换行 模版格式,图格式是最简单的格式,但实际效果不是这种,实际效果图如图2 图2 ,注意看红色部分,一对一是正常的,但是有一对多的订单 ...

  8. easyui datagrid 合并单元格

    整理以前做的东西,这个合并单元格的问题再新浪博客也写过了..... 下面这段代码是列表数据 //载入排放系数管理报表数据 function LoadEmissionReportData() { //获 ...

  9. GRIDVIEW多行多列合并单元格(合并列)

    GitHub项目地址:https://github.com/mingceng/merge-gridviewcell 去年的时候,我写了两篇文章:  GridView多行多列合并单元格(完整代码和例子) ...

随机推荐

  1. OpenCV 学习笔记 02 使用opencv处理图像

    1 不同色彩空间的转换 opencv 中有数百种关于不同色彩空间的转换方法,但常用的有三种色彩空间:灰度.BRG.HSV(Hue-Saturation-Value) 灰度 - 灰度色彩空间是通过去除彩 ...

  2. golang学习笔记---函数、方法和接口

    函数:对应操作序列,是程序的基本组成元素. 函数有具名和匿名之分:具名函数一般对应于包级的函数,是匿名函数的一种特例,当匿名函数引用了外部作用域中的变量时就成了闭包函数,闭包函数是函数式编程语言的核心 ...

  3. vc2010 属性值无效 灾难性故障 解决方法

    原文链接: http://blog.csdn.net/enterlly/article/details/8739281 说明: 我遇到这个问题是这样的,在为某个类添加消息时出现的.因为该类不在此工程的 ...

  4. SharePoint自动化部署,利用PowerShell 导入用户至AD——PART II

    这是对上一篇文章<SharePoint自动化部署,利用PowerShell 导出/导入AD中的用户>进行补充.开发时,为了测试和演示,我们往往需要经常性的把用户添加到AD中.数据量小的时候 ...

  5. hibernate的hql查询语句总结

    这篇随笔将会记录hql的常用的查询语句,为日后查看提供便利. 在这里通过定义了三个类,Special.Classroom.Student来做测试,Special与Classroom是一对多,Class ...

  6. [转]JDBC快速入门教程

    JDBC是什么? JDBC API是一个Java API,可以访问任何类型表列数据,特别是存储在关系数据库中的数据.JDBC代表Java数据库连接. JDBC库中所包含的API任务通常与数据库使用: ...

  7. 使用inno setup 制作安装文件-demo1

    ; 脚本由 Inno Setup 脚本向导 生成! ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "查体管理系统" # ...

  8. spring 项目中在类中注入静态字段

    有时spring 项目中需要将配置文件的属性注入到类的静态字段中 例如:文件上传 //文件上传指定上传位置 //resource-dev.properties 有如下参数 #upload UPLOAD ...

  9. 看MySQL官方文档的示例SQL有感

    [背景] 周末比较闲,我这个人又没有什么爱好,当然了读书除外:前一些天我一个同事说:“你一个dba想去写一本“django”书,合适吗?” 我想也是,一个人不能忘了本,所以MySQL还是要好好的搞一搞 ...

  10. C# string和byte[]的转换

    转自 http://www.cnblogs.com/Mainz/archive/2008/04/09/String_Byte_Array_Convert_CSharp.html string类型转成b ...