Extjs gridpanel 合并单元格
/*
* *合并单元格的函数,合并表格内所有连续的具有相同值的单元格。调用方法示例:
* *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 合并单元格的更多相关文章
- extjs grid合并单元格
http://blog.csdn.net/kunoy/article/details/7829395 /** * Kunoy * 合并单元格 * @param {} grid 要合并单元格的grid对 ...
- C# 获取Excel中的合并单元格
C# 获取Excel中的合并单元格 我们在制作表格时,有时经常需要合并及取消合并一些单元格.在取消合并单元格时需要逐个查找及取消,比较麻烦.这里分享一个简单的方法来识别Excel中的合并单元格,识别这 ...
- jquery操作表格 合并单元格
jquery操作table,合并单元格,合并相同的行 合并的方法 $("#tableid").mergeCell({ cols:[X,X] ///参数为要合并的列}) /** * ...
- NPOI操作EXCEL(五)——含合并单元格复杂表头的EXCEL解析
我们在第三篇文章中谈到了那些非常反人类的excel模板,博主为了养家糊口,也玩命做出了相应的解析方法... 我们先来看看第一类复杂表头: ...... 博主称这类excel模板为略复杂表头模板(蓝色部 ...
- poi获取合并单元格内的第一行第一列的值
当读取如图所示的excel时,显示为第1行 第1列 的内容是:合并单元格 其它在合并单元格区域内的单元格不显示 示例代码如下: import java.io.FileInputStream; impo ...
- Repeater多列分别合并单元格
GridView.Repeater合并单元格可以参考http://www.cnblogs.com/zhmore/archive/2009/04/22/1440979.html,但是原文例子是合并一列的 ...
- Aspose.Cells 首次使用,用到模版填充数据,合并单元格,换行
Aspose.Cells 首次使用,用到模版填充数据,合并单元格,换行 模版格式,图格式是最简单的格式,但实际效果不是这种,实际效果图如图2 图2 ,注意看红色部分,一对一是正常的,但是有一对多的订单 ...
- easyui datagrid 合并单元格
整理以前做的东西,这个合并单元格的问题再新浪博客也写过了..... 下面这段代码是列表数据 //载入排放系数管理报表数据 function LoadEmissionReportData() { //获 ...
- GRIDVIEW多行多列合并单元格(合并列)
GitHub项目地址:https://github.com/mingceng/merge-gridviewcell 去年的时候,我写了两篇文章: GridView多行多列合并单元格(完整代码和例子) ...
随机推荐
- 【struts2】Struts2的运行流程
1)前提条件 在讲解流程之前,假设我们已经建立了的一个名为strutsDeepen的web工程,该工程仅仅实现了简单的用户登陆与欢迎界面.具体的实现为: 在web.xml中配置了Struts2的过滤器 ...
- Redis快速入门及应用
Redis的使用难吗?不难,Redis用好容易吗?不容易.Redis的使用虽然不难,但与业务结合的应用场景特别多.特别紧,用好并不容易.我们希望通过一篇文章及Demo,即可轻松.快速入门并学会应用.一 ...
- ListView点击Item展开隐藏项(单项展开、多项展开、复杂布局时的展开处理)
手机屏幕毕竟有限,当我们要显示较多数据时便不得不舍去一些次要信息.将主要信息优先显示,也使显示效果更加简洁美观.遇到类似的需求,我们使用最多的就是 ListView ,而假设每次点击一个 Item 都 ...
- linux 命令中的find locate whereis which type 使用区别
find 最强大,但参数也较多,需指定查找目录,如 find / -name “filename” locate 是一个快速查找命令,有预先索引好的数据库,由于数据库是定时更新,因此,结果上可能会有迟 ...
- FreeSWITCH取消Digest校验流程
方法一.通过使用acl配置 <list name="domains" default="deny"> <!-- domain= is spec ...
- sqlserver使用存储过程发送http请求
本文主要向大家介绍了SQLServer数据库访问发送Http请求,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助. -- 通用读取获取数据存储过程 --开启Sql Serve ...
- Android自己定义view之measure、layout、draw三大流程
自己定义view之measure.layout.draw三大流程 一个view要显示出来.须要经过測量.布局和绘制这三个过程,本章就这三个流程具体探讨一下.View的三大流程具体分析起来比較复杂,本文 ...
- pm2 设置开机启动
一.官方文档: 官方相关文档:http://pm2.keymetrics.io/docs/usage/startup/#generating-a-startup-script 二.具体操作过程如下: ...
- logstash 中multiline插件的用法
input { stdin { codec =>multiline { charset=>... #可选 字符编码 max_bytes=>... #可选 bytes类型 设置最大的字 ...
- php分享二十五:跨域请求
问题: 跨域请求有几种方式? jsonp支持哪几种请求方式? 支持post请求吗? 支持get请求吗? 由于浏览器同源策略,凡是发送请求url的协议.域名.端口三者之间任意一与当前页面地址不同即为跨域 ...