easyui-datagrid-automatically merge cells (go)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.