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 ...
随机推荐
- Aix 文件名补齐及aix6.1 bash安装
Aix历史查询快捷键=>按ESC+k 设置KSH的自动补全(仅仅是文件名补全,没有命令补全)和历史命令功能 方法一: set -o vi 历史命令功能(esc -,esc +)自动补全文件名(e ...
- SQL 字段里有逗号隔开的数据的取值
table 1 : id code1 0012 001,0023 001,002,003 table 2:code name001 数学002 体育003 美术 要求结果 id name1 数学2 数 ...
- SQL Server执行计划那些事儿(2)——查找和扫描
接下来的文章是记录自己曾经的盲点,同时也透漏了自己的发展历程(可能发展也算不上,只能说是瞎混).当然,一些盲点也在工作和探究过程中慢慢有些眉目,现在也愿意发扬博客园的奉献精神,拿出来和大家分享一下. ...
- 第一个OC类、解析第一个OC程序
01第一个OC 类 本文目录 • 一.语法简介 • 二.用Xcode创建第一个OC的类 • 三.第一个类的代码解析 • 四.添加成员变量 • 五.添加方法 • 六.跟Java的比较 • 七.创建对象 ...
- 20160115--Hibernate
package com.hanqi.dao; import static org.junit.Assert.*; import java.util.*; import org.hibernate.se ...
- WEBGL 2D游戏引擎研发系列 第一章 <新的开始>
WEBGL 2D游戏引擎研发系列 第一章 <新的开始> ~\(≥▽≤)/~HTML5游戏开发者社区(群号:326492427) 转载请注明出处:http://html5gamedev.or ...
- Android Studio git ignore
# Built application files *.apk *.ap_ # Files for the Dalvik VM *.dex # Java class files *.class # G ...
- Flink资料(1)-- Flink基础概念(Basic Concept)
Flink基础概念 本文描述Flink的基础概念,翻译自https://ci.apache.org/projects/flink/flink-docs-release-1.0/concepts/con ...
- 向mysql添加新用户并分配权限
首先要声明一点,大部分情况下,修改MySQL是需要有mysql里的root权限的,所以一般用户无法更改密码,除非请求管理员. 方法一使用phpmyadmin,这是最简单的了,修改mysql库的user ...
- java设计模式之 单例模式 Singleton
static 的应用 单例模式 Singleton 单例:保证一个类在系统中最多只创建一个实例. 好处:由于过多创建对象实例,会产生过多的系统垃圾,需要GC频繁回收,由于GC会占用较大的系统资源,所有 ...