Article From:https://www.cnblogs.com/ztfcb/p/9967509.html

Recently, before collating the work records, there are a lot of information to learn from others, personal testing is effective. Unfortunately, the original records did not leave a source, such as infringement, please contact fourO4@163.com.

1.autoRowSpanThe first parameter of the function is the ID of the table.

2.The merged rows must be right-to-left and bottom-to-top, i.e. the second and third parameters are large to small, respectively.

<table class=”table table-bordered”  width=”auto”  id=”tab”>

    autoRowSpan(tab,0,4);
    autoRowSpan(tab,0,3);
    autoRowSpan(tab,0,2);
    autoRowSpan(tab,0,1);
    autoRowSpan(tab,0,0);

function autoRowSpan(tb,row,col)
{
    var lastValue="";
    var value="";
    var pos=1;
    for(var i=row;i<tb.rows.length;i++){
        value = tb.rows[i].cells[col].innerText;
        if(lastValue == value){
            tb.rows[i].deleteCell(col);
            tb.rows[i-pos].cells[col].rowSpan = tb.rows[i-pos].cells[col].rowSpan+1;
            pos++;
        }else{
            lastValue = value;
            pos=1;
        }
    }
}

 

Link of this Article: JS merged multi-row tables

Leave a Reply

Your email address will not be published. Required fields are marked *