1. Merge Method
/**
* Easyui DataGrid dynamically merges cells based on fields
* Tableid: ID of the table to be merged
* Columns whose collist parameter is to be merged are separated by commas (,) (for example, "name, department, office ");
*/
Function mergecellsbyfield (tableid, collist ){
VaR colarray = collist. Split (",");
VaR tTable = $ ("#" + tableid );
VaR tablerowcnt = tTable. DataGrid ("getrows"). length;
VaR tmpa;
VaR tmpb;
VaR pertxt = "";
VaR curtxt = "";
VaR alertstr = "";
For (j = colarray. Length-1; j> = 0; j --){
Pertxt = "";
Tmpa = 1;
Tmpb = 0;
For (I = 0; I <= tablerowcnt; I ++ ){
If (I = tablerowcnt ){
Curtxt = "";
}
Else {
Curtxt = tTable. DataGrid ("getrows") [I] [colarray [J];
}
If (pertxt = curtxt ){
Tmpa + = 1;
}
Else {
Tmpb + = tmpa;
TTable. DataGrid ("mergecells ",{
Index: I-tmpa,
Field: colarray [J], // merge Fields
Rowspan: tmpa,
Colspan: NULL
});
TTable. DataGrid ("mergecells", {// merge Based on colarray [J]
Index: I-tmpa,
Field: "ideparture ",
Rowspan: tmpa,
Colspan: NULL
});
Tmpa = 1;
}
Pertxt = curtxt;
}
}
}
2. Call the merge Method
// Present the list data
$ ('# List'). DataGrid ({pagination: True,
Onloadsuccess: function (data ){
If (data. Rows. length> 0 ){
// Call mergecellsbyfield () to merge Cells
Mergecellsbyfield ("tblist", "no ");
}
}
});
Note:
Mergecellsbyfield (tableid, collist );
ID of the table to be merged
Columns to be merged with the collist parameter, separated by commas (,) (for example, "name, department, office ");
This method is generally not used because it is not beautiful.
Suppose:
1 |
1 |
1 |
1 |
5 |
1 |
1 |
5 |
1 |
1 |
5 |
2 |
1 |
1 |
2 |
As follows:
Due to the limitations of the table, we cannot merge the third column. If we merge three "1" and two "2", we will understand why it is not beautiful.
Haha, based on the red section in my method, we use one primary column, and the others are merged based on the number of its rows. Success
Thank you very much.
Http://www.gogogogo.me/development/EasyUI-DataGrid-mergeCells.html