62,046
社区成员
发帖
与我相关
我的任务
分享
01.#region 合并单元格(自动合并转为人工合并)
02.private void SetMergeCells(Infragistics.WebUI.UltraWebGrid.UltraWebGrid uwgReport,string key)
03.{
04. for (int i = 0; i < uwgReport.Columns.Count; i++)
05. {
06. string str = "";
07. string text = "";
08. int num2 = 0;
09.
10. if (uwgReport.Columns[i].MergeCells)
11. {
12. uwgReport.Columns[i].MergeCells = false;
13.
14. if (uwgReport.Rows.Count > 0)
15. {
16. text = uwgReport.Rows[0].Cells.FromKey(key).Text;
17.
18. for (int j = 0; j < uwgReport.Rows.Count; j++)
19. {
20. str = uwgReport.Rows[j].Cells.FromKey(key).Text;
21.
22. if (str != text)
23. {
24. text = str;
25. uwgReport.Rows[num2].Cells[i].ColSpan = 1;
26. uwgReport.Rows[num2].Cells[i].RowSpan = j - num2;
27. num2 = j;
28. }
29. }
30. uwgReport.Rows[num2].Cells[i].ColSpan = 1;
31. uwgReport.Rows[num2].Cells[i].RowSpan = uwgReport.Rows.Count - num2;
32. }
33. }
34. }
35.}
36.#endregion
/*
* 功能说明:把传入的所有单元格中连续的且内容一样的合并,通常是针对于垂直方向相邻的连续单元格
* 函数用法:传入一个jquery选择器表达式即可,如:mergeTd("#tb .td0")
* 用法举例:如想把某表格(其id是tb)的第一列进行合并操作,可以把第一列的单元格的样式名全部设置为td0,然后调用mergeTd("#tb .td0")
* 使用须知:需要引用jquery1.2.3
*/
function mergeTd(tdCls,attrName,isDebug)
{
if(!attrName)
{
attrName="rowspan";
}
if(typeof isDebug=="undefined")
{
isDebug=false;
}
var rowspan=1;
var first=null;
var lastHtml=null;
var tmpNode=null;
var currHtml="";
if(isDebug)
{
document.write(tdCls+"<br>");
}
$(tdCls).each(
function()
{
currHtml=$(this).html();
if(currHtml==lastHtml)
{
rowspan++;
if(isDebug)
{
$(this).css("color","red");
$(this).html("需要删除");
tmpNode.html(attrName+"="+rowspan);
}
else
{
$(this).remove();
tmpNode.attr(attrName,rowspan);
}
}
else
{
tmpNode=$(this);
if(isDebug)
{
tmpNode.css("color","green");
}
lastHtml=currHtml;
rowspan=1;
}
});
}