layui dynamic table of cells merged

 demand:

The following probably excel spreadsheet simulation with lower demand, the left is the original, the right to change this:

 

① Step: After calling this method regenerated form to merge duplicate cells

 done : function(res, curr, count) {
        merge(res);
 }

 

② The second step: write this method:

 

Merge function (RES) {

var = Data res.data;
var = 0 MergeIndex; // positioned rows to add merge attribute
var mark = 1; // herein relates to a simple calculation, mark is calculated for each of the need to merge grid number
var columsName = [ 'id', 'name']; // needs combined column name
var columsIndex = [0,1]; // to be merged column index value

for (var k = 0; k <columsName. length; k ++) {// cycle where all the column to
var trArr = $ ( "layui- table-body> .layui-table.") find ( "tr");. // all rows
for (var i = 1; i <res.data.length; i ++ ) {// cycle where the current data table
var tdCurArr = trArr.eq (i) .find ( "td") eq (columsIndex [k]);. // Get the current line current column
var tdPreArr = trArr.eq (mergeIndex) .find ( "td") eq (columsIndex [k]);. // Get the same column of the first row

if (data [i] [columsName [k]] === data [i-1] of the previous row value [[k] columsName]) {// the line for comparison, the same need to merge
Mark + =. 1;
tdPreArr.each (() {// first row of the same column increasing function attributes rowspan
$ (the this) .attr ( "rowspan", Mark);
});
tdCurArr.each (function () {// current line hidden
$ (the this) .css ( "the display", "none");
});
} {the else
MergeIndex = I;
mark =. 1; // once the values of the two longitudinal rows is not the same, then the number of the grid to be merged need to be recalculated mark
}
}
MergeIndex 0 =;
mark =. 1;
}
}

Guess you like

Origin www.cnblogs.com/nc923/p/11288072.html