/*
* *合并单元格的函数,合并表格内所有连续的具有相同值的单元格。调用方法示例:
* *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. 【Algorithm】插入排序

    一. 算法描述 插入排序具体算法描述如下: 从第一个元素开始,该元素可以认为已经被排序 取出下一个元素,在已经排序的元素序列中从后向前扫描 如果该元素(已排序)大于新元素,将该元素移到下一位置 重复步 ...

  2. 忙里偷闲写的小例子---读取android根目录下的文件或文件夹

    最近几天真的是各种意义上的忙,忙着考试,还要忙着课程设计,手上又有外包的项目,另一边学校的项目还要搞,自己的东西还在文档阶段,真的是让人想死啊!! 近半个月来,C#这方面的编码比较多,android和 ...

  3. mysql - tmp_table_size & max_heap_table_size

    Command-Line Format --tmp_table_size=# System Variable Name tmp_table_size Variable Scope Global, Se ...

  4. Java/Android倒计时(开始,暂停,恢复,停止)

    由于要做暂停和恢复,这里我就没有使用Android的CountDownTimer,而是用了Java的Timer.所以,这个方法在java肯定是通用.我也外加了Android独有的Service,有些计 ...

  5. appium简明教程(3)——appium的安装windows版

    appium的哲学里有一条就是不重新发明轮子.同样,官方已经有明确的安装步骤了,因此在这里纯属搬砖. 原文地址 感谢testerhome的辛勤翻译. 本文版权归乙醇所有,欢迎转载,但请注明作者与出处, ...

  6. C#操作Sqlite快速入门及相关工具收集

    Sqlite不需要安装即可使用.Sqlite是不是那个System.Data.SQLite.DLL临时创建了数据库引擎? 1.新建一个WinForm项目,引用System.Data.SQLite.DL ...

  7. python标准库介绍——31 threading 模块详解

    threading 模块 (可选) ``threading`` 模块为线程提供了一个高级接口, 如 [Example 3-1 #eg-3-1] 所示. 它源自 Java 的线程实现. 和低级的 ``t ...

  8. C#基础第五天-作业-用DataTable制作名片集

    1.用DataTable集合去实现名片集.(增加,修改,删除,查询,查询全部)需求:根据人名去(删除/查询).指定列:姓名,年龄,性别,爱好,电话. 本系列教程: C#基础总结之八面向对象知识点总结- ...

  9. springboot 整合 Redis 方法二

    方法一请参考之前博文 spring boot 整合 redis 自己的版本  java8 + redis3.0 + springboot 2.0.0 1 spring boot已经支持集成 redis ...

  10. UIButton 标题靠右

    _classBtn =  [UIButton buttonWithType:UIButtonTypeCustom]; _classBtn.frame = CGRectMake(  kDeviceWid ...