javascript - Merge table rows based on row text and class -


i have found function here , suits needs. function iterates through first column of table, , row merges similar values. then, iterates through next column, , row merges values well, while taking account merges of column before it. in way, suits need.

function mergecommonrows2(table, firstonly) {     var firstcolumnbrakes = [];     (var = 1; <= table.find('th').length; i++) {         var previous = null, celltoextend = null, rowspan = 1;         table.find("td:nth-child(" + + ")").each(function (index, el) {             if (previous == $(el).text() && $(el).text() !== "" && $.inarray(index, firstcolumnbrakes) === -1) {                 $(el).addclass('hidden');                 celltoextend.attr("rowspan", (rowspan = rowspan + 1));             } else {                 if (firstonly == 'first only') {                     if (i === 1)                         firstcolumnbrakes.push(index);                 } else {                     if ($.inarray(index, firstcolumnbrakes) === -1)                         firstcolumnbrakes.push(index);                 }                 rowspan = 1;                 previous = $(el).text();                 celltoextend = $(el);             }         });     } } 

however, wish edit function consider classes well. in other words, wish edit function first check classes of 2 rows being merged. and, if have same value, if have different classes, not merge rows. have tried edit above function much, no avail.


update

my attempts edit code quite crude. essentially, put code before if statement adds hidden class , said, summarize, if previous.getclass = current.getclass, go onto if statement hides class.

here fiddle. want click merge button and, since "click me" cells have different classes between them, don't want them merge.


Popular posts from this blog