ASPxGridView-单元格合并
<dx:ASPxGridView ID="gridView" runat="server" ClientInstanceName="gvResults" Width="550px"
AutoGenerateColumns="True" KeyFieldName="OrderID" DataSourceID="AccessDataSource1">
</dx:ASPxGridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT * FROM [Orders]"></asp:AccessDataSource>
<script type="text/javascript">
window.__OriginalDXUpdateRowCellsHandler = ASPxClientTableFixedColumnsHelper.prototype.ChangeCellsVisibility;
ASPxClientTableFixedColumnsHelper.prototype.ChangeCellsVisibility = function(row, startIndex, endIndex, display) {
if((row.cells.length == 0) || (row.cells[0].getAttribute("ci") == null))
window.__OriginalDXUpdateRowCellsHandler(row, startIndex, endIndex - 1, display); // base call
else {
//custom processing
for(var i = startIndex; i <= endIndex; i++) {
var cell = FindCellWithColumnIndex(row, i);
if(cell != null)
cell.style.display = display;
}
}
};
function FindCellWithColumnIndex(row, colIndex) {
for(var i = 0; i < row.cells.length; i++) {
if(row.cells[i].getAttribute("ci") == colIndex)
return row.cells[i];
}
return null;
}
=================================
protected void Page_Load(object sender, EventArgs e) {
if (!(IsPostBack || IsCallback))
gridView.DataBind();
new ASPxGridViewCellMerger(gridView);
gridView.Columns[0].FixedStyle = GridViewColumnFixedStyle.Left;
gridView.Columns[1].FixedStyle = GridViewColumnFixedStyle.Left;
gridView.Columns[0].CellStyle.BackColor = Color.FromArgb(0xEE, 0xEE, 0xEE);
gridView.Columns[1].CellStyle.BackColor = Color.FromArgb(0xEE, 0xEE, 0xEE);
gridView.Settings.ShowHorizontalScrollBar = true;
}
===========CellMerger.cs=====================
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;
using System.Collections.Generic;
public class ASPxGridViewCellMerger {
ASPxGridView grid;
Dictionary<GridViewDataColumn, TableCell> mergedCells = new Dictionary<GridViewDataColumn, TableCell>();
Dictionary<TableCell, int> cellRowSpans = new Dictionary<TableCell, int>();
public ASPxGridViewCellMerger(ASPxGridView grid) {
this.grid = grid;
Grid.HtmlRowCreated += new ASPxGridViewTableRowEventHandler(grid_HtmlRowCreated);
Grid.HtmlDataCellPrepared += new ASPxGridViewTableDataCellEventHandler(grid_HtmlDataCellPrepared);
}
public ASPxGridView Grid { get { return grid; } }
void grid_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e) {
//add the attribute that will be used to find which column the cell belongs to
e.Cell.Attributes.Add("ci", e.DataColumn.VisibleIndex.ToString());
if (cellRowSpans.ContainsKey(e.Cell)) {
e.Cell.RowSpan = cellRowSpans[e.Cell];
}
}
void grid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e) {
if (Grid.GetRowLevel(e.VisibleIndex) != Grid.GroupCount) return;
for (int i = e.Row.Cells.Count - 1; i >= 0; i--) {
DevExpress.Web.ASPxGridView.Rendering.GridViewTableDataCell dataCell = e.Row.Cells[i] as DevExpress.Web.ASPxGridView.Rendering.GridViewTableDataCell;
if (dataCell != null) {
MergeCells(dataCell.DataColumn, e.VisibleIndex, dataCell);
}
}
}
void MergeCells(GridViewDataColumn column, int visibleIndex, TableCell cell) {
bool isNextTheSame = IsNextRowHasSameData(column, visibleIndex);
if (isNextTheSame) {
if (!mergedCells.ContainsKey(column)) {
mergedCells[column] = cell;
}
}
if (IsPrevRowHasSameData(column, visibleIndex)) {
((TableRow)cell.Parent).Cells.Remove(cell);
if (mergedCells.ContainsKey(column)) {
TableCell mergedCell = mergedCells[column];
if (!cellRowSpans.ContainsKey(mergedCell)) {
cellRowSpans[mergedCell] = 1;
}
cellRowSpans[mergedCell] = cellRowSpans[mergedCell] + 1;
}
}
if (!isNextTheSame) {
mergedCells.Remove(column);
}
}
bool IsNextRowHasSameData(GridViewDataColumn column, int visibleIndex) {
//is it the last visible row
if (visibleIndex >= Grid.VisibleRowCount - 1)
return false;
return IsSameData(column.FieldName, visibleIndex, visibleIndex + 1);
}
bool IsPrevRowHasSameData(GridViewDataColumn column, int visibleIndex) {
ASPxGridView grid = column.Grid;
//is it the first visible row
if (visibleIndex <= Grid.VisibleStartIndex)
return false;
return IsSameData(column.FieldName, visibleIndex, visibleIndex - 1);
}
bool IsSameData(string fieldName, int visibleIndex1, int visibleIndex2) {
// is it a group row?
if (Grid.GetRowLevel(visibleIndex2) != Grid.GroupCount)
return false;
return object.Equals(Grid.GetRowValues(visibleIndex1, fieldName), Grid.GetRowValues(visibleIndex2, fieldName));
}
}
ASPxGridView-单元格合并的更多相关文章
- ExtJS 4.2 Grid组件的单元格合并
ExtJS 4.2 Grid组件本身并没有提供单元格合并功能,需要自己实现这个功能. 目录 1. 原理 2. 多列合并 3. 代码与在线演示 1. 原理 1.1 HTML代码分析 首先创建一个Grid ...
- NPOI 教程 - 2.1单元格合并
来源:http://liyingchun343333.blog.163.com/blog/static/3579731620091018212990/ 合并单元格在制作表格时很有用,比如说表格的标题就 ...
- asp.net使用控件datagrid实现表头单元格合并
合并的要点: 1.datagid的单元格合并原理是table中tr,td的布局实现; 2.合并的时机实在其datagridcreate事件中实现; 3.认识一个对象TableCellCollectio ...
- DataGridView单元格合并
本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...
- devexpress实现单元格合并以及依据条件合并单元格
1.devexpress实现单元格合并非常的简单,只要设置属性[AllowCellMerge=True]就可以了,实现效果如下图: 2.但是在具体要求中并非需要所有的相同单元格都合并,可能需要其他的条 ...
- SNF快速开发平台MVC-表格单元格合并组件
1. 表格单元格合并组件 1.1. 效果展示 1.1.1. 页面展现表格合并单元格 图 4.1 1.1.2. 导出excel合并单元格 图 4.2 1.2. 调用说 ...
- 关于table动态添加数据 单元格合并 数组合并
var newArr = [ {"BranchID":1,"BranchName":"城二","BranchFullName&qu ...
- excel技巧--单元格合并与拆分
如果要将上图的地区列做成下图的合并单一列: 有如下做法: (以下图表格为例) 1.选择要排序的表格,点击“开始”-->排序和筛选-->自定义排序.在对话框选择“业务项目”进行排序: 2.选 ...
- element-ui table 最后一行合计,单元格合并
接着写两个方法--最后一行合计的方法 --单元格合并的方法 先写一个rowspan方法,计算出spanArr数组是怎么单元格合并的,注意rowspan方法要在渲染完成之前使用,可以在mounted中使 ...
- 如何通过DataGridView 实现单元格合并和二维表头
先看下实现出来的效果(这里随便写了几组数据,用来测试) 先初始一个DataGridView 设置哪几列 DataGridView 里男女这两列的 AutoSizeMode 可以设置Fill. publ ...
随机推荐
- C语言入门(20)——使用VC2013对C语言进行调试
软件调试过程中,有时会一些逻辑和内存访问方面的问题,如果没有调试器的帮助,找出何处代码导致这块内存被更改是一件非常麻烦的事情.恰当运用数据断点可以快速帮我们定位问题的所在. 1.VC的调试快捷键 F5 ...
- iOS 唯一设备号
https://github.com/fabiocaccamo/FCUUID 目前比较好的解决方案.
- How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- 自己动手写CPU之第五阶段(3)——MIPS指令集中的逻辑、移位与空指令
将陆续上传本人写的新书<自己动手写CPU>(尚未出版),今天是第17篇.我尽量每周四篇 5.4 逻辑.移位操作与空指令说明 MIPS32指令集架构中定义的逻辑操作指令有8条:and.and ...
- JavaScript 工作必知(九)function 说起 闭包问题
大纲 Function Caller 返回函数调用者 Callee 调用自身 作用域 闭包 function 函数格式 function getPrototyNames(o,/*optional*/ ...
- 动画原理——线性来回运动&&波动
书籍名称:HTML5-Animation-with-JavaScript 书籍源码:https://github.com/lamberta/html5-animation 1.在正选函数中,随角度的增 ...
- C# 与 VB.NET 对比
C# 与 VB.NET 对比 2008-06-20 15:30 by Anders Cui, 1462 阅读, 3 评论, 收藏, 编辑 Table of Contents 1.0 Int ...
- 浅谈print2flash的在线预览转换应用(原创)
print2flash是一种在线预览转换工具,可以将doc.docx.xls.pdf.ppt等格式的文档转换成flash文件进行预览,因为之前使用的flash2paper只支持32为操作系统,不支持6 ...
- Linux学习awk命令
awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各 ...
- 如果不知道MySQL当前使用配置文件(my.cnf)的路径的解决方法
如果不知道当前使用的配置文件的路径,可以尝试下面的操作: # which mysqld /usr/local/mysql/bin/mysqld # /usr/local/mysql/bin/mysql ...