인터넷에 일반반적으로 있는 방식 (같으면 무조건 머지)

$.fn.rowspan = function (colIdx, isStats) {
            return this.each(function () {
                var that;
                $('tr', this).each(function (row) {
                    $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {

                        if ($(this).html() == $(that).html()
                            && (!isStats
                                    || isStats && $(this).prev().html() == $(that).prev().html()
                                    )
                            ) {
                            rowspan = $(that).attr("rowspan") || 1;
                            rowspan = Number(rowspan) + 1;

                            $(that).attr("rowspan", rowspan);

                            // do your action for the colspan cell here           
                            $(this).hide();

                            //$(this).remove();
                            // do your action for the old cell here

                        } else {
                            that = this;
                        }

                        // set the that if not already set
                        that = (that == null) ? this : that;
                    });
                });
            });
        };

 

사용 : $('#gvList').rowspan(1); => gvList는 테이블 이름

 

하지만, 이건 단일 col에대한 것만 머지를 한다

 

 

 

단일 col이 아니고 특정 col에 대해서도 같냐 아니냐를 구분해서 머지를 시켜 줘야한다면

emptyTrScript += "    <td class='data_AC' id='tdTargetYear'>";
emptyTrScript += "        <span id='lblTargetYear'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC' id='tdSalesUserId'>";
emptyTrScript += "        <span id='lblSalesUserId_'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC' id='tdTargetPer'>";
emptyTrScript += "        <span id='lblTargetPer'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC' id='tdGUBUN'>";
emptyTrScript += "        <span id='lblGUBUN'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC' id='tdCUST01_'>";
emptyTrScript += "        <span id='lblCUST01_'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC'>";
emptyTrScript += "        <span id='lblCUST04_'></span>";
emptyTrScript += "    </td>";

 

function fnGridMerger() {
            var TargetYear_nextThat;
            var TargetYear_mergeThat;
            var TargetYear_rowspan = 1;
            var TargetYear_nextValue;
            var TargetYear_thisValue;

            var SalesUserId_nextThat;
            var SalesUserId_mergeThat;
            var SalesUserId_rowspan = 1;
            var SalesUserId_nextValue;
            var SalesUserId_thisValue;

            var TargetPer_nextThat;
            var TargetPer_mergeThat;
            var TargetPer_rowspan = 1;
            var TargetPer_nextValue;
            var TargetPer_thisValue;

            var GUBUN_nextThat;
            var GUBUN_mergeThat;
            var GUBUN_rowspan = 1;
            var GUBUN_nextValue;
            var GUBUN_thisValue;

            var CUST01__nextThat;
            var CUST01__mergeThat;
            var CUST01__rowspan = 1;
            var CUST01__nextValue;
            var CUST01__thisValue;

            $('#gvList').find("tr").each(function () {
                $(this).next().find("td").each(function () {
                    var id = $(this).attr("id");

                    // 년도
                    if (id == "tdTargetYear") {
                        TargetYear_nextValue = $(this).html();

                        TargetYear_nextThat = $(this);
                    }

                    // 영업담당자
                    if (id == "tdSalesUserId") {
                        SalesUserId_nextValue = $(this).html();

                        SalesUserId_nextThat = $(this);
                    }

                    // 달성율
                    if (id == "tdTargetPer") {
                        TargetPer_nextValue = $(this).html();

                        TargetPer_nextThat = $(this);
                    }

                    // 구분(목표, 실적)
                    if (id == "tdGUBUN") {
                        GUBUN_nextValue = $(this).html();

                        GUBUN_nextThat = $(this);
                    }

                    // 구분(순매출, 매출)
                    if (id == "tdCUST01_") {
                        CUST01__nextValue = $(this).html();

                        CUST01__nextThat = $(this);
                    }
                });

                $(this).find("td").each(function () {
                    var id = $(this).attr("id");

                    // 년도
                    if (id == "tdTargetYear") {
                        TargetYear_thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (TargetYear_nextValue == TargetYear_thisValue) {
                                TargetYear_rowspan += 1;

                                TargetYear_mergeThat = $(this);

                                $(TargetYear_nextThat).hide();
                            }
                            else {
                                TargetYear_mergeThat = null;
                                TargetYear_rowspan = 1;
                            }
                        }
                        else {
                            if (TargetYear_nextValue == TargetYear_thisValue) {
                                TargetYear_rowspan += 1;

                                $(TargetYear_mergeThat).attr("rowspan", TargetYear_rowspan - 1);

                                $(TargetYear_nextThat).hide();
                            }
                            else {
                                $(TargetYear_mergeThat).attr("rowspan", TargetYear_rowspan);
                                TargetYear_mergeThat = null;
                                TargetYear_rowspan = 1;
                            }
                        }
                    }

                    // 영업담당자
                    if (id == "tdSalesUserId") {
                        SalesUserId_thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                SalesUserId_rowspan += 1;

                                SalesUserId_mergeThat = $(this);

                                $(SalesUserId_nextThat).hide();
                            }
                            else {
                                SalesUserId_mergeThat = null;
                                SalesUserId_rowspan = 1;
                            }
                        }
                        else {
                            if (SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                SalesUserId_rowspan += 1;

                                $(SalesUserId_mergeThat).attr("rowspan", SalesUserId_rowspan - 1);

                                $(SalesUserId_nextThat).hide();
                            }
                            else {
                                $(SalesUserId_mergeThat).attr("rowspan", SalesUserId_rowspan);
                                SalesUserId_mergeThat = null;
                                SalesUserId_rowspan = 1;
                            }
                        }
                    }

                    // 달성율
                    if (id == "tdTargetPer") {
                        TargetPer_thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                TargetPer_rowspan += 1;

                                TargetPer_mergeThat = $(this);

                                $(TargetPer_nextThat).hide();
                            }
                            else {
                                TargetPer_mergeThat = null;
                                TargetPer_rowspan = 1;
                            }
                        }
                        else {
                            if (TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                TargetPer_rowspan += 1;

                                $(TargetPer_mergeThat).attr("rowspan", TargetPer_rowspan - 1);

                                $(TargetPer_nextThat).hide();
                            }
                            else {
                                $(TargetPer_mergeThat).attr("rowspan", TargetPer_rowspan);
                                TargetPer_mergeThat = null;
                                TargetPer_rowspan = 1;
                            }
                        }
                    }

                    // // 구분(목표, 실적)
                    if (id == "tdGUBUN") {
                        GUBUN_thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (GUBUN_nextValue == GUBUN_thisValue && TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                GUBUN_rowspan += 1;

                                GUBUN_mergeThat = $(this);

                                $(GUBUN_nextThat).hide();
                            }
                            else {
                                GUBUN_mergeThat = null;
                                GUBUN_rowspan = 1;
                            }
                        }
                        else {
                            if (GUBUN_nextValue == GUBUN_thisValue && TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                GUBUN_rowspan += 1;

                                $(GUBUN_mergeThat).attr("rowspan", GUBUN_rowspan - 1);

                                $(GUBUN_nextThat).hide();
                            }
                            else {
                                $(GUBUN_mergeThat).attr("rowspan", GUBUN_rowspan);
                                GUBUN_mergeThat = null;
                                GUBUN_rowspan = 1;
                            }
                        }
                    }

                    // 구분(순매출, 매출)
                    if (id == "tdCUST01_") {
                        CUST01__thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (CUST01__nextValue == CUST01__thisValue && GUBUN_nextValue == GUBUN_thisValue && TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                CUST01__rowspan += 1;

                                CUST01__mergeThat = $(this);

                                $(CUST01__nextThat).hide();
                            }
                            else {
                                CUST01__mergeThat = null;
                                CUST01__rowspan = 1;
                            }
                        }
                        else {
                            if (CUST01__nextValue == CUST01__thisValue && GUBUN_nextValue == GUBUN_thisValue && TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                CUST01__rowspan += 1;

                                $(CUST01__mergeThat).attr("rowspan", CUST01__rowspan - 1);

                                $(CUST01__nextThat).hide();
                            }
                            else {
                                $(CUST01__mergeThat).attr("rowspan", CUST01__rowspan);
                                CUST01__mergeThat = null;
                                CUST01__rowspan = 1;
                            }
                        }
                    }
                });
            });
        }

+ Recent posts

인터넷에 일반반적으로 있는 방식 (같으면 무조건 머지)

$.fn.rowspan = function (colIdx, isStats) {
            return this.each(function () {
                var that;
                $('tr', this).each(function (row) {
                    $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {

                        if ($(this).html() == $(that).html()
                            && (!isStats
                                    || isStats && $(this).prev().html() == $(that).prev().html()
                                    )
                            ) {
                            rowspan = $(that).attr("rowspan") || 1;
                            rowspan = Number(rowspan) + 1;

                            $(that).attr("rowspan", rowspan);

                            // do your action for the colspan cell here           
                            $(this).hide();

                            //$(this).remove();
                            // do your action for the old cell here

                        } else {
                            that = this;
                        }

                        // set the that if not already set
                        that = (that == null) ? this : that;
                    });
                });
            });
        };

 

사용 : $('#gvList').rowspan(1); => gvList는 테이블 이름

 

하지만, 이건 단일 col에대한 것만 머지를 한다

 

 

 

단일 col이 아니고 특정 col에 대해서도 같냐 아니냐를 구분해서 머지를 시켜 줘야한다면

emptyTrScript += "    <td class='data_AC' id='tdTargetYear'>";
emptyTrScript += "        <span id='lblTargetYear'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC' id='tdSalesUserId'>";
emptyTrScript += "        <span id='lblSalesUserId_'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC' id='tdTargetPer'>";
emptyTrScript += "        <span id='lblTargetPer'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC' id='tdGUBUN'>";
emptyTrScript += "        <span id='lblGUBUN'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC' id='tdCUST01_'>";
emptyTrScript += "        <span id='lblCUST01_'></span>";
emptyTrScript += "    </td>";
emptyTrScript += "    <td class='data_AC'>";
emptyTrScript += "        <span id='lblCUST04_'></span>";
emptyTrScript += "    </td>";

 

function fnGridMerger() {
            var TargetYear_nextThat;
            var TargetYear_mergeThat;
            var TargetYear_rowspan = 1;
            var TargetYear_nextValue;
            var TargetYear_thisValue;

            var SalesUserId_nextThat;
            var SalesUserId_mergeThat;
            var SalesUserId_rowspan = 1;
            var SalesUserId_nextValue;
            var SalesUserId_thisValue;

            var TargetPer_nextThat;
            var TargetPer_mergeThat;
            var TargetPer_rowspan = 1;
            var TargetPer_nextValue;
            var TargetPer_thisValue;

            var GUBUN_nextThat;
            var GUBUN_mergeThat;
            var GUBUN_rowspan = 1;
            var GUBUN_nextValue;
            var GUBUN_thisValue;

            var CUST01__nextThat;
            var CUST01__mergeThat;
            var CUST01__rowspan = 1;
            var CUST01__nextValue;
            var CUST01__thisValue;

            $('#gvList').find("tr").each(function () {
                $(this).next().find("td").each(function () {
                    var id = $(this).attr("id");

                    // 년도
                    if (id == "tdTargetYear") {
                        TargetYear_nextValue = $(this).html();

                        TargetYear_nextThat = $(this);
                    }

                    // 영업담당자
                    if (id == "tdSalesUserId") {
                        SalesUserId_nextValue = $(this).html();

                        SalesUserId_nextThat = $(this);
                    }

                    // 달성율
                    if (id == "tdTargetPer") {
                        TargetPer_nextValue = $(this).html();

                        TargetPer_nextThat = $(this);
                    }

                    // 구분(목표, 실적)
                    if (id == "tdGUBUN") {
                        GUBUN_nextValue = $(this).html();

                        GUBUN_nextThat = $(this);
                    }

                    // 구분(순매출, 매출)
                    if (id == "tdCUST01_") {
                        CUST01__nextValue = $(this).html();

                        CUST01__nextThat = $(this);
                    }
                });

                $(this).find("td").each(function () {
                    var id = $(this).attr("id");

                    // 년도
                    if (id == "tdTargetYear") {
                        TargetYear_thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (TargetYear_nextValue == TargetYear_thisValue) {
                                TargetYear_rowspan += 1;

                                TargetYear_mergeThat = $(this);

                                $(TargetYear_nextThat).hide();
                            }
                            else {
                                TargetYear_mergeThat = null;
                                TargetYear_rowspan = 1;
                            }
                        }
                        else {
                            if (TargetYear_nextValue == TargetYear_thisValue) {
                                TargetYear_rowspan += 1;

                                $(TargetYear_mergeThat).attr("rowspan", TargetYear_rowspan - 1);

                                $(TargetYear_nextThat).hide();
                            }
                            else {
                                $(TargetYear_mergeThat).attr("rowspan", TargetYear_rowspan);
                                TargetYear_mergeThat = null;
                                TargetYear_rowspan = 1;
                            }
                        }
                    }

                    // 영업담당자
                    if (id == "tdSalesUserId") {
                        SalesUserId_thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                SalesUserId_rowspan += 1;

                                SalesUserId_mergeThat = $(this);

                                $(SalesUserId_nextThat).hide();
                            }
                            else {
                                SalesUserId_mergeThat = null;
                                SalesUserId_rowspan = 1;
                            }
                        }
                        else {
                            if (SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                SalesUserId_rowspan += 1;

                                $(SalesUserId_mergeThat).attr("rowspan", SalesUserId_rowspan - 1);

                                $(SalesUserId_nextThat).hide();
                            }
                            else {
                                $(SalesUserId_mergeThat).attr("rowspan", SalesUserId_rowspan);
                                SalesUserId_mergeThat = null;
                                SalesUserId_rowspan = 1;
                            }
                        }
                    }

                    // 달성율
                    if (id == "tdTargetPer") {
                        TargetPer_thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                TargetPer_rowspan += 1;

                                TargetPer_mergeThat = $(this);

                                $(TargetPer_nextThat).hide();
                            }
                            else {
                                TargetPer_mergeThat = null;
                                TargetPer_rowspan = 1;
                            }
                        }
                        else {
                            if (TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                TargetPer_rowspan += 1;

                                $(TargetPer_mergeThat).attr("rowspan", TargetPer_rowspan - 1);

                                $(TargetPer_nextThat).hide();
                            }
                            else {
                                $(TargetPer_mergeThat).attr("rowspan", TargetPer_rowspan);
                                TargetPer_mergeThat = null;
                                TargetPer_rowspan = 1;
                            }
                        }
                    }

                    // // 구분(목표, 실적)
                    if (id == "tdGUBUN") {
                        GUBUN_thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (GUBUN_nextValue == GUBUN_thisValue && TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                GUBUN_rowspan += 1;

                                GUBUN_mergeThat = $(this);

                                $(GUBUN_nextThat).hide();
                            }
                            else {
                                GUBUN_mergeThat = null;
                                GUBUN_rowspan = 1;
                            }
                        }
                        else {
                            if (GUBUN_nextValue == GUBUN_thisValue && TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                GUBUN_rowspan += 1;

                                $(GUBUN_mergeThat).attr("rowspan", GUBUN_rowspan - 1);

                                $(GUBUN_nextThat).hide();
                            }
                            else {
                                $(GUBUN_mergeThat).attr("rowspan", GUBUN_rowspan);
                                GUBUN_mergeThat = null;
                                GUBUN_rowspan = 1;
                            }
                        }
                    }

                    // 구분(순매출, 매출)
                    if (id == "tdCUST01_") {
                        CUST01__thisValue = $(this).html();

                        if ($(this).is(":visible")) {
                            if (CUST01__nextValue == CUST01__thisValue && GUBUN_nextValue == GUBUN_thisValue && TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                CUST01__rowspan += 1;

                                CUST01__mergeThat = $(this);

                                $(CUST01__nextThat).hide();
                            }
                            else {
                                CUST01__mergeThat = null;
                                CUST01__rowspan = 1;
                            }
                        }
                        else {
                            if (CUST01__nextValue == CUST01__thisValue && GUBUN_nextValue == GUBUN_thisValue && TargetPer_nextValue == TargetPer_thisValue && SalesUserId_nextValue == SalesUserId_thisValue && TargetYear_nextValue == TargetYear_thisValue) {
                                CUST01__rowspan += 1;

                                $(CUST01__mergeThat).attr("rowspan", CUST01__rowspan - 1);

                                $(CUST01__nextThat).hide();
                            }
                            else {
                                $(CUST01__mergeThat).attr("rowspan", CUST01__rowspan);
                                CUST01__mergeThat = null;
                                CUST01__rowspan = 1;
                            }
                        }
                    }
                });
            });
        }

+ Recent posts