Easyui-DataGrid-automatically merge cells ()

Source: Internet
Author: User

1. Objectives

1.1 after the table Initialization is complete, the rows to be merged are automatically merged;

1.2 click the sort field and merge it again;

2. Implementation

2.1 introduce plug-ins

/*** Author ____ '* 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) {var before, after, megerindex = group [0]; for (VAR I = 0; I <group. length; I ++) {before = group [I]; after = group [I + 1]; If (after & & (After-before) = 1) {continue;} var rowspan = before-megerindex + 1; if (rowspan> 1) {target. dataGrid ('mergecells ', {index: megerindex, field: field, rowspan: rowspan});} If (after & (after-before )! = 1) {megerindex = after ;}}}});});});}});

2.2html code

<table id="simpleDgId" style="height: 300px" />

2.3js code

VaR sortflag = false; $ ('# simpledgid'). DataGrid ({URL: "testcontroller. do? DataGrid ", fitcolumns: True, singleselect: True, remotesort: false, columns: [{field:" Age ", title:" Age ", width: 25, align: 'center', sortable: true}, {field: "username", title: "name", width: 25, align: 'center', sortable: true}, {field: "mobilephone", title: "Mobile Phone", width: 25, align: 'center', sortable: true}], onsortcolumn: function (sort, order) {sortflag = true; if ("username" = sort) {$ (this ). dataGrid ("automergecells", [sort]) ;} Else {$ (this). DataGrid ("automergecells") ;}}, onloadsuccess: function (data) {If (! Sortflag) $ (this). DataGrid ("automergecells ");}});

2.4 background

URL: "testcontroller. do? DataGrid"

Background Data is common table data, which is not described here

2.5 results

 

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.