Recently, when working on a project, you need to merge the cells in the GridView to display the same data into a row. A big brother in the company wrote this and pasted it to the bit for a look, if the company's Code cannot be obtained, you can understand it and write it by yourself.
TabObj indicates the table Id, that is, the Id of the GridView. cellIndex indicates the column number to be merged. beignRow indicates the number of rows from which the table is merged. Generally, 1 is used because 0 indicates the table header.
The js Code is as follows:
Function SpanGrid (tabObj, cellindex, beginRow ){
Var colIndex = cellindex;
Var rowBeginIndex = beginRow;
If (tabObj! = Null ){
Var I, j, m;
Var intSpan;
Var strTemp;
M = 0;
For (I = rowBeginIndex; I <tabObj. rows. length; I ++ ){
IntSpan = 1;
M ++;
StrTemp = tabObj. rows [I]. cells [colIndex]. innerText;
For (j = I + 1; j <tabObj. rows. length; j ++ ){
If (strTemp = tabObj. rows [j]. cells [colIndex]. innerText ){
IntSpan ++;
TabObj. rows [I]. cells [colIndex]. rowSpan = intSpan;
TabObj. rows [j]. cells [colIndex]. style. display = "none ";
}
Else {
Break;
}
}
}
I = j-1;
}
}
Of course, this Js Code has a small problem, that is, only one column can be merged, and multiple columns cannot be merged at the same time. I hope a friend can improve it so that it can merge multiple columns at the same time.