1. Target
1.1 After the initialization of the table is completed, the rows that need to be merged are automatically merged;
1.2 When you click on a field to sort, re-merge;
2. Implement
2.1 Introducing Plugins
/** * Author ____′ summer throb * Create Date 2012-11-5 * **/$.extend ($.fn.datagrid.methods, {automergecells:function(JQ, fields) {Return Jq.each (function() {var target = $ (This);if (!Fields) {fields = Target.datagrid ("Getcolumnfields"); }var rows = Target.datagrid ("GetRows");var i = 0, j = 0, temp ={};for (i; i < rows.length; i++) {var row =Rows[i]; j = 0;For (J; J < Fields.length; J + +) {var field =FIELDS[J];var tf =Temp[field];if (!TF) {tf = Temp[field] ={}; Tf[row[field]] =[i]; }Else{var TFV =Tf[row[field]];If(TFV) {Tfv.push (i);}Else{TFV = Tf[row[field]] =[i]; }}}} $.each (temp,function(field, COLUNM) {$.each (COLUNM,function() {var group =This;if (Group.length > 1) {VarBefore, after, Megerindex = Group[0];for (var i = 0; i < group.length; I++) {before = Group[i]; after = group[i + 1]; if (After && (after-before) = = 1continuevar rowspan = before-megerindex + 1 if (rowspan > 1if (After && (after-before)! = 1) {Megerindex =< Span style= "color: #000000;" > after; } } } }); }); }); }});
2.2html Code
<id= "simpledgid" style/>
2.3JS Code
var Sortflag =False; $ (' #simpleDgId '). DataGrid ({URL: "Testcontroller.do?datagrid"), Fitcolumns:True, Singleselect:True, Remotesort:False, columns:[[{field: "Age", Title: "Ages", Width:25,align: ' Center ', sortable:True}, {field: "UserName", Title: "Name", Width:25,align: ' Center ', sortable:True}, {field: "Mobilephone", Title: "Mobile", Width:25,align: ' Center ', sortable: truefunction (sort, order) {Sortflag = trueif ("UserName" ==sort) {$ ( this). DataGrid ("Automergecells" ,[sort]);} else{$ (this). DataGrid ("Automergecells" if (!sortflag) $ (this). DataGrid ("Automergecells"
2.4 Backstage
URL: "Testcontroller.do?datagrid"
Background data is the normal form of data, here will not repeat the
2.5 effects
easyui-datagrid-automatically merge cells (go)